Home > Projects > Pick to Light Project 2 WiFi

Pick to Light Project 2 WiFi

Summary of Pick to Light Project 2 WiFi


This project converts a serial pick-to-light prototype to WiFi using an Arduino MKR1000 and UDP. A Python script reads a CSV sequence, sends sequence and bin over UDP, and waits for the MKR1000 to light the correct LED and return the sequence as acknowledgement. If the acknowledgement mismatches, the Python program stops to allow restart. The system uses a button to confirm picks, and a transistor workaround for LED power issues when WiFi is active. Code for both Arduino and Python and wiring notes are provided.

Parts used in the Pick to Light UDP Project 2:

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

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

Quick Solutions to Questions related to Pick to Light UDP Project 2:

  • What does this project change compared to project 1?
    It replaces serial cable communication with WiFi using UDP and adds sequence-number acknowledgements.
  • What hardware is required to run the project?
    The project uses an Arduino MKR1000, two LEDs, jumper wires, a 12mm pushbutton, resistors (10k and four 330 ohm), a breadboard, USB-A to Micro-USB cable, and an NPN transistor.
  • How does the Python script communicate with the Arduino?
    The Python script sends sequence and bin data over UDP to the Arduino IP and port and waits for the Arduino to reply with the sequence number.
  • How is sequence integrity ensured?
    The Python script compares the sequence number received from the Arduino to the last sequence sent and stops with an error if they differ.
  • What does the Arduino do when it receives a UDP packet?
    The Arduino parses the sequence and bin, lights the corresponding LED, waits for the button press, then turns off the LED and sends the sequence back as acknowledgement.
  • Why is a transistor used in the LED circuitry?
    The transistor is used as a workaround because enabling WiFi on the MKR1000 caused voltage drop on pins 8 and 9 preventing LEDs from illuminating.
  • What must be configured for the MKR1000 to join WiFi?
    The SSID and password must be placed in the arduino_secrets.h secret file and the WiFi101 library should be available.
  • How is the sequence file formatted and used?
    The sequence file is a CSV with 4-digit sequence numbers and bin names separated by a comma (for example 0001,Bin1) and is read line by line by the Python script.
  • How can a sequence failure be tested?
    The article shows modifying the Arduino reply to send a wrong sequence (e.g., hardcoding 0001) which causes the Python program to report a sequence fault and stop.

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
Scroll to Top