From API to LED: Duplex Communication

Friday night! The perfect time for expanding on the API-to-LED work from last week. The improvement now offers a more diverse set of information and utilizes duplex serial communication.

The result is that now we can now use a toggle-switch to see the 1-hour price change of either Bitcoin or Ethereum in the form of LED lights. The position of the attached toggle switch determines which currency is being shown.

The programming also features a p5 sketch that reflects the information being sent through the serial.

For example, in the video below Ethereum has had a modest positive 1 hour price change (0.06%), so it lights up the green LEDs a teeny bit. At the same time, Bitcoin has had a larger, negative price change (-1.16%), so it lights up the red LEDs quite a bit.

As you indicated by the diagram below, the information is exchanged through the serial port in two directions:

The p5 and Arduino code are both available here. Again, this code will only work if you have your serial ports set up correctly (with p5.serialcontrol).

This specific Arduino code corresponds with the following setup (sorry, I could not find any green LED icons):

The code and setup as-is is vexed with two minor issues:

  1. The thresholds to determine the extremity of the gain or loss. Current this value is set in the code as 2%. This means that if the change is greater than 2% or less than -2%, we won’t see any change to the LED. There is currently no way to change the threshold on the fly, and the threshold is not determined in any mathematical way. I just chose two. A solution to this would be to call data from the API that can be used to create a maximum and minimum for the percentage values.
  2. The buffer of the data from the API. Over time (hours) the buffer time between the Arduino and p5 increase to a noticeable amount due to the ‘delay’ command currently used in the Arduino’s loop function. This buffer may be fixed by a better synchronization of the timing of the two programs. To be tweaked.

The ultimate goal of the project is still to remove the computer from the operation.

As a next step we will try Bluetooth, Radio, or Wireless communication to the Arduino so we can at least remove the physical connection of the LEDs to the computer. Stay tuned!

PS: shouts out to the ITP residents for all of their help with serial communications so far. Thanks!

One thought on “From API to LED: Duplex Communication”

Leave a Reply

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