Assignment 14 Communication



The Arduiono-Clone communicates

I started by developing my Ardiono-Clone from the Output-Assignment from the One-Pin-Layout to a Multi-Pin-Layout. Then I wired to Microcontrolles so the can communicate with each other in the simplest way possible. Lastly I used a bluethooth-module to control my clone with my phone.

Cloning an Arduino



As you can see the changes to the circuit are very minor. I just added a pinheader for each pin of the ATMega.


Same goes for the board layout. I placed the headers like the pinouts of the ATMega as far as it was possible.


Bluetooth communication

For this task im using a DSD TECH HM-10 Bluetooth-module. The module is connected via the Serial port of the ATMega. Since I use the Serial port sometimes to debug my boards I used this library to create an additional serial with the pins D8 and D9. Wire it up like in the picture. In the picture there is an Arduinio but the wiring is the same for the Fakeduino. The Voltage devider is needed since the pin voltage of the ATmega is 5V but the HM-10 need 3.3V. The divider scales it down to roughly 3.3V. You can use every combination of resistor als long as one is twice as large as the other.
BLE uses a number of predefined services a full list can be found here. But in the following I only use custom services.


For this task im using a DSD TECH HM-10 Bluetooth-module. The module is connected via the Serial port of the ATMega. To communicate with it I use the App "BLE-Scanner" , this i only for testing purposes, later on I will program my own app for the final project. Just download the app from the google play store. The app is pretty straight forward you can receive bluetooth messages and send them via a textfield. Just select the device you want to communicate with from the list in my case it was named DSD-Tech and hit connect. If you now select the the custom service tab you can "talk" to the BLE module. Now hit the "N"-button to be able to receive messages. When you hit the "W"-button you can send a message by typing it into the textfield that pops up.
Look in the video at bottom to see how it works live. For troubleshooting and more about how to work with the HM-10 refer to this tutorial.



In computer combination there are many reasons why a message is not correctly submitted (noise,loss of data,superposition of different messages). To counter that I developed a simple message protocol: [A:B:payload]
Here "A" and "B" a single bytes of Data (One Letter or number) and "payload" can consist of multiple bytes.
The controller reads the serial input of the bluetooth-module till a "[" is received then every byte including the "[" is saved until a "]" is received after that the message is processed. If an other "[" everything previously saved will be overridden because the first message was not transmitted correctly since is has no "]".
The first step of the message processing is a sort of integrity check here the format of the message is checked. Right number of colons right position of colons (see Template above). Then the message is split up into the "A","B" and "payload" parts, this will be relevant in my final project to address groups of leds.
Example: [1:2:512]->Leds in subgroup 2 of group 1 change color to 512
For now the code [0:0:1] sets on an Led and the code [0:0:0] turns it of when sent to the microcontroller.

This protocol is ver help full when dealing with multiple in and outputs because you can simply group and subgroup (first two entries) them


Remember Initialize the Bluetooth serial by calling BTSerial.begin() in trhe setup function. In the code snipped you can see how the bits sent to the BLE module from the phone are read and saved in a buffer.
When the BLE module receives a message BTserial.available() is true now the message can be read bit by bit via the command BTserial.read(). In this case the programm waits for an "[" in stream and the writes the following message into the buffer incoming using the variable c.
To send stuff from the microcontroller simply use the command BTserial.write("some message").

Other Protocols

I2C
With the Serial clock pin (SCL) and the Serial Data pin(SDA) the Attiny45 can use the I2C protocol. To communicate on of the processors has to be the master and the others the slaves. (one master can have multiple s laves but not the other way around). Each slave has an 7-bit address. The master has no address and generates the clock signal for all slave so everything is synced.
WS28/12
The WS28/ Led stripes use a one way communication method where in each message has a predefined length and each receiver takes a part of the message. SO the first 3 bits are for receiver 1 the secon 3 bits for receiver two and so on. more can be found in my Output-Assignment

Favourite beverage of the Assignment


Just black tea to stay awake and maybe to hunt some Wyvern