Pick to Light Project 2 WiFi

In the second project in my pick to light, I am using WIFI to pass the data between PC and Arduino.

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1
LED (generic)
LED (generic)
× 2
Jumper wires (generic)
Jumper wires (generic)
× 1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
× 1
Resistor 10k ohm
Resistor 10k ohm
× 1
Resistor 330 ohm
Resistor 330 ohm
× 4
Breadboard (generic)
Breadboard (generic)
× 1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
× 1
General Purpose Transistor NPN
General Purpose Transistor NPN
× 1

Story

Python Script to be run.
## load the necessary libraries
import csv
import socket
import time
import sys

UDP_IP = "192.168.1.119" ## the ip of our Arduino
UDP_PORT = 2390 ## the port we wish to communicate on

print("UDP target IP:", UDP_IP) ## display ip to user
print("UDP target port:", UDP_PORT) ## display port to user

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # create a socket


time.sleep(5)
##open csv file and read it in one line at a time
with open('sequence1.txt') as csvDataFile: 
    csvReader = csv.reader(csvDataFile)
    for row in csvReader: ##for each line do the following
        myseq = row[0] ##read in the sequence number
        mystate = row[1] ##read in the bin number
        myrow = row[0] + row[1]
        print("Current sequence being picked ",myseq,"from ", mystate)
        sock.sendto(bytes(myrow, "utf-8"), (UDP_IP, UDP_PORT)) # send seq and bin number
        data = "" # set data to blank to enter while loop i=until data is received
        while data == "": # until data is received keep looping through
            (data, addr) = sock.recvfrom(1024) # set data to data received from socket
            mytest = data.decode( "utf-8") #set mytest to equal value received over socket
            print ("picked = ", mytest) # print the value received
            if mytest != myseq: # test what has ben received matches what was expected i.e. last seq sent
                print ("there is a sequence fault at sequence", mytest) # display message to indicate a fault
                sys.exit() #end program execution if fault exists

Sequence

Plain text

Sequence file for the python program
0001,Bin1
0002,Bin2
0003,Bin1
0004,Bin2
0005,Bin1
0006,Bin2
0007,Bin1
0008,Bin2
0009,Bin1
0010,Bin2
0011,Bin1
0012,Bin2
0013,Bin1

 

Source : Pick to Light Project 2 WiFi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top