Networking and Communications

Week 3

Introduction

Introduction

I created an app in the Applications week which allows the user to pick a color on a color wheel and send it to the lamp in RGB values, I have since been trying to get the RN4871 chip to interface with the app and the rgb circuit, but it has not worked so far. Perhaps if the hello board for the RN4871 included an attiny45 with the necessary code to put the RN4871 into server mode, so that it could be interacted with, this would simplify the process. I have not been able to make this work so far, but hopefully someone with more programming experience could figure this out in the future.

Meanwhile, I created a phototransistor board that can communicate to multiple LED boards to control all of them simultaneously. The pieces are designed to fit inside the casing of my final project. Included is code for the LED boards so that they will shine "white" by flashing all the lights in a very rapid sequence so it appears to be a constant white light.

Anyone who wishes to try this for themselves can grab my code pack and feel free to experiment.

Individual Assignment Code pack

Making things speak and listen when you want them to

Networking and communication

Getting started

The goal for this assignment was to create a simple network of circuits using softwareSerial in the Arduino IDE. With my charlieplexed rgb LED board as the output and the phototransistor as the input, I had a good base to build on. The main thing I needed to make sure of was that each board has a 2x2 pin header for the bus, where the pins are Ground, V, Rx and Tx. It's also imperative that ground and voltage are in the same place on each one. If not, the microcontroller will get fried, which I learned the hard way when I was rushing to connect my boards. Smoke rushed out, and I had to remove, replace and resolder the regulator and the microcontroller.


The LED boards

Three LED boards will sit at the base of my lamp. Each one has 14 rgb LEDs, equalling a total of 126 individual LEDs. The boards are rounded and sized to fit inside the housing of the lamp. The code for these boards listens for commands. When they receive a command, they check if it differs from the old command, in which case they switch states, then set the new command as the old command and wait for the next message. In this case, there is only either "on" or "off". This board took quite a bit of trouble-shooting. The board is two-sided, and the first milling of it was slightly crooked, so the holes are not perfectly aligned. This made it more difficult to solder, and I had a few shorts that needed to be taken care of, as well as a few places where a pin was soldered in, but not connected to the trace, causing an interrupted signal. A few wires took care of these issues.


The phototransistor board

The network relies on a single phototransistor to tell it when to turn on or off. The most difficult part of this circuit was to figure out how to send a signal only when the threshold was crossed, and not every time the lightlevel shifted. Also, I tried for a long time to send "o" and "O" but in the end, it failed because I was meant to send 'o' and 'O' with single apostrophes instead of quotation marks. Once this bug was uncovered, I was still receiving a great deal of artefacts, because I had forgotten to burn the bootloader, so the internal clock wasn't working. I burned the bootloader, and now the board communicates smoothly.


The code

The code is relatively simple once it has been written, but it took a while to figure it out. I included the softwareSerial.h library, because the tiny's do not have hardware serial communication. I then used the "if (mySerial.available())" command, because if it is not available, the board will send failure messages, which is not helpful. I used mySerial.print and mySerial.read to communicate between the boards, and of course, I made sure that the rxPin on my LED board connects to the txPin on the phototransistor board and vise versa.


Addressing

This is a very simple type of network. Communication is required from the phototransistor to the LED boards, and not the other way around. Additionally, they all receive the same signal at the same time; On or Off. In order to introduce the bluetooth module to this network, more complicated communication will be required. This would require the individual boards to know when to listen. I expect the easiest method would be to designate the boards so that the bluetooth board only sends signals to the phototransistor board, which only sends to the LED boards. No board would send anything to the bluetooth board that way.

Still, even such a simple network requires the boards to only listen to specific messages, ignoring irrelevant chatter. I need the phototransistor to listen only when the ble board is transmitting, and I need the LED boards to only listen to messages from the phototransistor. Because they are all on the same bus, this requires addressing. (To be fair, I could also do this by modifying the bus, removing the connection to the LED tx and the BLE rx, so that the bus would essentially be a one-way street like so: BLE tx -> Phototrans rx, phototrans tx -> LED rx.) For the sake of this experiment, let's say we do not want to remove the connections physically. I need to decide that the LED boards only listen if the messages is addressed to them, and the phototransistor only listens if the message is addressed to it.


Listening for specific messages

I wanted to stick with the Arduino programming interface and the softwareSerial library. Given these limitations, I determined that the easiest thing to do would be to make the devices listen only to specific messages. This way, the PT(phototransistor) board is only listening for specific lower case 'char's, the LED boards are only listening for specific upper case 'char's and the BLE board is only listening for integers and will ignore letters. This way, the PT board can transmit the light level values, and the LED boards will ignore this, while the BLE board makes sense of it. Likewise, the PT board can send R, G, B, W or o commands which the BLE board will ignore, but the LED boards will react to. Finally, because the values transmitted from the BLE board are r, g, b and w, the LED boards will ignore this, the same way it ignores the integers from the PT board.

I realize that this is not the same as having unique IDs for each board, but it works, and it is doable within the environment I've learned to use. It is also similar to the method used by Fab Academy 2018 graduate Rutuja Patel of CEPT.

Rutuja Patel-network assignment Updated code

conclusion

SoftwareSerial is a convenient way to create a simple network. I used to think that networks were much more difficult and intimidating, but Bas showed me how simple they can be, for which I am very grateful. Now that I have closed this loop, the second loop would be to add the rn4871 to the network and making it communicate with the other chips to determine the color they should display. Before I can do that, I will need to write the code that allows the color to be adjusted, and assemble the lamp properly.

Next page Fab Academy