For this week's assignment, I decided to make one new bridge board with ATTiny45 to communicate with computer and use previous boards I made in week 7 and week 11 on which have ATTiny44.
Making a bridge board
I referred to Neil's board and added a LED and a resistor. For designing the PCB, I followed the same sequence that I did in week 7. Here are the schematic and the board layout of the bridge board.
I followed the same sequence that I did in week 5 to mill the board and soldered the components. After I soldered the components, I checked conductivity of each pin and short circuit with multimeter.
Programming with Arduino IDE
My plan was to connect the bridge board with node on which has LED. The node board send 0 or 1 to the bridge board depending on the LED's state. The bridge board recieves 0 or 1 from the node board, and converts 0 to "OFF" or 1 to "ON" and send to the computer.
I started testing the board. I used simple Arduino sketch for serial communication which sends "A" to the serial monitor. Tx and rx pins on the bridge board worked, but somehow LED didn't turn on. I didn't have time to figure out so I decided not to use LED on the bridge board.
Next I tested the node board. I wrote a simple Arduino sketch which turns LED on and off for a sencond and sends value 0 when LED is off and value 1 when LED is on to the serial monitor. It worked.
I changed the pin number of rx and tx pins as I used MISO as rx pin and SCK as tx pin, so that the node board can send the value to the bridge board.
I connected the bridge board and the node board and ran the code.
First I messed up tx and rx pins on the node board. I set tx as OUTPUT, rx as INPUT, then connected tx on the node board to tx on the bridge board, rx on the node board to rx on the bridge board. But tx on the node board which is OUTPUT should have connected to rx on the bridge board which is INPUT. So I changed connections as tx on the node board is connected with rx on the bridge board, rx on the node board is connected with the bridge board. It worked.
Arduino serial monitor
Coolterm
I added one more board that I made in week 13 as node2. I changed the code so that:
If the LED on node1 turns on, write "NODE1 ON"
If the LED on node1 turns off, write "NODE1 OFF"
If the LED on node2 blinks, write "NODE2 BLINK"
First I tested the code with each boar separately. Each board worked fine.
With node1
With node2
I connected two node boards with bridge board. LEDs turned on but nothing was shown in seiral monitor.
Looking at Jari's documentation, I realised that I needed to default tx pin which send signals as input. By shatting down each tx pin when it is not used, all nodes can communicate. I modefied the code. Also while I was trying to make network work, I connected in a wrong pin (probably I made a short circuit) and echo hello-world board was disabled.. So I used the board for input device and the board for LED that I made in week 12 as node1. Now the network is working correctly.
Arduino sketch of the bridge board
Arduino sketch of node1, 2
Serial monitor
Update: addressing
I got feedback from Jani and realized that I need to address each node. I read Jari's and Kati's documentation to understand how to include addressing in Arduino sketch. I modified my Arduino sketch as below. For node boards, I added command to identify the node as:
const char node = '1';
And defined "incomingByte" which comes from the bridge board. In Void loop, I added condition for the node to listen if a signal from the bridge board is for the node or other node(s) as:
if (incomingByte == node)
And I wrote the commands to print message on the serial monitor including its ID.
Updated code for node 1:
Updated code for node 2:
For the bridge board, I defined Serial as serial communication with computer and mySerial as serial communication with nodes. Also I defined incomingByte as byte coming from the computer and myincomingByte as byte coming from nodes. In Arduino sketch, I defined txPin as the pin which recieves signal from computer and transmits to the nodes, and rxPin as the pin which recieves signal from nodes and transmits to the computer. I connected txPin on bridge board with rxPins on the node boards, and rxPin on the bridge board with txPins on the node boards. For mySerial and Serial, I defined pins as:
SoftwareSerial mySerial(rxPin,txPin);
SoftwareSerial Serial(txPin, rxPin);
In Void setup, I set rxPin as INPUT so that rxPin recieves signal from the nodes. In Void loop, I wrote commands 1) to recieve signals (incomingByte) from the computer (Serial) and transmit the signals to the nodes (mySerial), and 2) to recieve signals (myincomingByte) from the nodes (mySerial) and transmit the signals to the computer (Serial). To transmit the signals to the computer, I needed to use rxPin on the bridge board as OUTPUT. I created condition when mySerial recieves '1' or '2' (address of each node), use rxPin as OUTPUT so that it can transmit the signal to the computer. After that, rxPin goes back to INPUT again to listen signals from the nodes.
Updated code for the bridge:
Here is the result.
Reflection
This week, I learned how to build network where several baords are connected and communicate. I didn't have much time so I made a very simple network using my previous boards. Programming was not so difficult but I struggled with wiring. Since I used the boards I made before, each board has some differences, such as different pin order, different connections etc. So figuring out which wire should go which pin was challenging. I learned I should make boards using the same pins as much as I can. It will make wiring much easier. I wanted to try bluetooth module to connect with smartphone. I found many people used bluetooth module and built network, so I will have a look and try later.