Control a stack light via serial communications through an Arduino! To get this project setup and running will require minimal knowledge for wiring up an Arduino (and shield) to a light fixture.
This project uses the following hardware to operate:
You can use the following diagram to guide you in wiring everything together:
It's worth noting that although the relay shield has 4 relays, we are only using 3 since the stack light we are using only has 3 lights (red, green, yellow). We do not use the fourth relay, but it can still be controlled in commands sent.
Right now you can only communicate to the Arudino via serial communication. You can use the following to assist in this:
screen /dev/cu.usbmodel3111 19200
- Using the Serial Monitor in the Arduino IDE or VS Code extension
The Arudino software is set to run at 19200 baud. If you are seeing malformed/odd characters then make sure you have set the correct baud rate.
Each command will return the final relay status, which can be parsed as needed.
Command | Description | Example |
---|---|---|
? |
Print commands available | ? |
! |
Print relay status (on or off) | ! |
+ [relayNumber] |
Turn on a single relay or all relays (if not defined) | + 1 |
- [relayNumber] |
Turn off a single relay or all relays (if not defined) | - 1 |
/ |
Toggle a single relay or all relays (if not defined) | / 1 |
: [relayNumber] [iterationCount=1] [onTime=500] [offTime=500] [dwellTime=0] |
Flash one or all relays at once | : ? 3 500 500 500 |
~ [iterationCount=1] [onTime=200] [offTime=0] [dwellTime=0] |
Flash each relay in order | ~ 3 500 500 500 |
% |
Run demo mode | % |
It's much easier to use VS Code or another text editor/IDE instead of the very basic/limiting Arudino IDE.
- Install Arudino IDE for all system packages
- Add the Arduino extension to VSCode (
vsciot-vscode.vscode-arduino
) - Add the EditorConfig extension to VS Code (
EditorConfig.EditorConfig
)
This is only needed if you are looking to re-compile the Protobuf messages. This repo includes the current header files representing the current Protobuf messages.
- Install Python
brew install python
- Install Protobuf
brew install protobuf
- If you see a message about not being able to import the module run the suggested command:
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
- If you see a message about not being able to import the module run the suggested command:
- Install the NanoPB library
- Download the NanoPB repo as a .zip file
- Extract the .zip file contents to
~/Documents/Arduino/libraries/nanopb-master
- Alternatively you can do this within Arudino IDE via the Sketch > Include Library > Add .ZIP Library... menu item
- Run
make
in thegenerator/proto
directory
- Install the NanoPB Arduino bridge library
- Download the NanoPB-Arduino repo as a .zip file
- Extract the .zip file contents to
~/Documents/Arduino/libraries/nanopb-arduino-master
- Alternatively you can do this within Arudino IDE via the Sketch > Include Library > Add .ZIP Library... menu item
- Within the
nanopb-arduino-master
directory, move the contents of thesrc
folder up a level
- Make changes to the
commands.proto
file as needed - Navigate to the
arduino-controller/proto
directory - Run
./compile_pb.sh
to output header files- NOTE: Recompiling the entire Arduino project will be needed after to utilize the changes made
- Arudino to interface Relay shield to serial communications
- Code documentation
- Javascript wrapper library to assist with interfacing to Arudino via serial
- Expand Javascript library to connect to various application monitoring services