week_14

Networking and Communications

Assignments



Generality


Hello.light.45

Embedded electronics are created by interconnecting circuits (processors or other integrated circuits) to create symbiotic systems. In order for these individual circuits to exchange their information, they must share a common communication protocol. Hundreds of communication protocols have been defined for this data exchange, and generally each can be divided into two categories: parallel or serial.
"Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Many communication systems were generally designed to connect two integrated circuits on the same printed circuit board, connected by signal traces on that board (rather than external cables)."Some low-cost serial buses include SPI, I2C, DC-BUS, UNI/O, and 1-Wire.

SPI

SPI mode usually has one master device and one or more slave devices, requiring at least 4 wires, and in fact 3 wires can be used (for one-way transmission).Also common to all SPI based devices are MISO (primary device data input), MOSI (primary device data output), SCLK (clock), CS (chip selection).
(1) MISO -- Master Input Slave Output, data Input from the Master device and data Output from the Slave device;
(2) MOSI -- Master Output Slave Input, data Output of the Master device and data Input from the Slave device;
(3) SCLK -- Serial Clock, Clock signal, generated by the main device;
(4) CS -- Chip Select, enabling signal from the slave device, controlled by the master device.

I2C

I2C bus is a simple, two - way two - line synchronous serial bus developed by Philips. It requires only two wires to transmit information between devices connected to the bus. The I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL) that the master board pulses at regular interval, and a serial data pin (SDA) over which data is sent between the two devices.

Group Assignment


In my group assignment, I am planning that to connect my ultrasonic sensor input driver which made in week 09 and RGB output driver which made in week 11.

Program the ultrasonic sensor driver

First, I referred the schematic diagrams for the ultrasonic sensor input driver.

...


...


Here is the board of the ultrasonic sensor input driver.

...


Then I used the Arduino IDE to program. Then I program the codes like this:

...


This part of the program is connected to the ultrasonic sensor interface. It is the premise that simply initializes the ultrasonic sensor, takes readings, and outputs the data in serial. At each read, a "#" is inserted to mark the end of one read and the beginning of the next.

Program the ultrasonic sensor driver

I also read the schematic diagram of RGB board.

...


Here is the RGB board.

...


The program codes like this

...


...


This part of the program is for RGB LED panel, which accepts serial data from another panel. The data is received by character the '#' is found, reset the values. if a sequence decimal is found, it’s converted to a number. This number, if less than 10 the RED led in the RGB led is lit up with the appropriate brightness. If more than 10 and less than 20, RED is lit with full brightness and GRENN with the brightness corresponding to the distance, similarly for the distance between 20 and 30. For more than 30 all are lit with full brightness. But it didn’t work. I don’t know why.

...


Individual assignment


I2C Connection

(1) Eagle
This week I only designed the master board because I would use boards created previously on week_06. The designed in Eagel and the necessary components for producing the board are shown below.

...


...


(2) PCB Production
I used the Roland SRM-20 milling machine, controlled with mods to mill the board, following the same process as in Electronics Design week.

...


(3) Programing
I used Arduino IDE to program I2C communication codes. In my case, the master device was connected to one slave device, the board for a LED and a button created previously on week_06.
① Master device

...


② Slave code

...


Setting the environment
In this case, there has a problem when I first I tried to use “Wire.h” for the slave board using ATtiny44, which is the library could not be used.

...


So I search the problem in the fablab, I found the page that shows how to execute Wire.h in Attiny44. From this web page, additional board manager library file was required. All files and tutorial are shown here.
A. File->Preferences on a PC, or Arduino->Preferences on a Mac, enter the above URL in "Additional Boards Manager URLs.

...


B. Tools -> Boards -> Boards Manager... *If using 1.6.6, close boards manager and re-open it (see below)

...


C. Select "ATTinyCore by Spence Konde" and click "Install".
After I completed to install new board manager library file, I could compile the code for the slave device.
④ Wiring
Actual wiring is shown below.

...


Pull-up registers were already included in Master board, so just wiring power, GND, SDA, and SCL was enough to prepare I2C communication.

Hello.attiny44.bus

(1) Eagle
I also used eagle to start getting my board designed. I used an ATTiny44 instead of an ATTiny45, I was able to spare several more pins for new features. I also added an input (2 pins) of a temperature sensor, which uses a grouping of 3 resistors and one thermistor. Also, I've left traces for an output pin leading to a small heating element that can be powered off 5 V.
The bridge node has an FTDI cable to interface with the computer. The necessary components for producing the board are the following:

...


...


The slave nodes are identical to the bridge in wiring. They just lack an FTDI cable because they will be connected to everything they need via the serial bus. The necessary components for producing the board are the following:

...


...


(2) PCB Production
I used the Roland SRM-20 milling machine, controlled with mods to mill the board, following the same process as in Electronics Design week.

...


...


(3) Connecting a Bus
he first thing to do is to configure the bus. So, in order to program, I have to insert the connections in a certain order. In addition, I chose to share the programmer's SCK line with RX, so your master board must be flashed clean to start programming other nodes, or it might pull up or down the SCK line. Here is the order which I connect:
① Connect FTDI cable (1*6 pin), programmer cable (2*3 Pin) and serial bus cable (2*2 Pin) to Bridge Board.
② Flash Bridge Node.
③ Connect usbtiny programmer cable to Node Board.
④ Link Node Board to the serial bus coming from Bridge Board.
⑤ Program Node Board with node bus.
⑥ Unlink Node Board completely.
⑦ Repeat Steps 2-5 for all Node Boards, separately.
⑧ Connect usbtiny programmer cable back to Bridge Board.
⑨ Program Bridge Board with bridge bus.
⑩ Connect in the working configuration as shown.
(4) Programing a Bus
I wrote code in Arduino IDE to frame data through the serial bus. I let the Master Board to make all the shots. In a loop, Master Board send the frame message "1", "2", "3" and "4". Then it will send a node ID, 1 or 2, and then it will send a number representing a function from the board, such as a flashing LED. Here is the Master board code:
#include
const int cycle_delay = 1;/// Define a constant periodic delay time of 1ms

SoftwareSerial mySerial(7, 4);/// Define serial port receive (RX), send (TX) pins

void setup() {
mySerial.begin(9600); // Baud rate of serial port monitor
pinMode(3, OUTPUT); / Define the pin 3 output mode
}

void requestTemp(int id) {
mySerial.write(1); mySerial.write(2); mySerial.write(3); mySerial.write(4); // Send serial port commands
mySerial.write(id); // Send serial port commands
mySerial.write(8); // Send serial port commands

delay(200);// Waiting for 200 ms
}
void loop() {
digitalWrite(3, LOW); //turn the LED on
delay(200); //Waiting for 200 ms
digitalWrite(3, HIGH); //turn the LED off
delay(200);//Waiting for 200 ms

delay(cycle_delay); //let them shine
}
And here is the Slave board 1 code. Remember to change the node ID from another programming to the next:
#include
const int node_id = 1; // Define a constant the number of slave board;
int b1,b2=0,b3=0,b4=0; //Define constant of b1、b2、b3、b4=0
int id_read = 0; //Define a constant id_read = 0

SoftwareSerial mySerial(4, 7); // Define serial port receive (RX), send (TX) pins

int blue_pin = 3; //Define the LED pin to be constant blue_pin = 3
int blue_duty = 0;

void setup(){
mySerial.begin(9600); // Baud rate of serial port monitor
pinMode(blue_pin,OUTPUT); //set up led pins as outputs
}

void read_duties(){
while(mySerial.available() == 0);//Determine whether the serial port has received data,enter the loop when the condition is met
id_read = mySerial.read(); //keep reading till something, read serial port data assignment to constant id_read
if (id_read == node_id){ //Determines whether the constant ID_read is equal to the number of nodes
while(mySerial.available() == 0);
therm_duty = mySerial.read();
}
}

void loop(){

if(mySerial.available() != 0){
b1=b2; b2=b3; b3=b4;
b4 = mySerial.read();
if(b1==1 && b2==2 && b3==3 && b4==4){ //Conditions for LED lights to turn on/off
read_duties();

digitalWrite(blue_pin,LOW); //turn the LED on
delay (500); //Waiting for 500 ms
digitalWrite(blue_pin,HIGH); //turn the LED off
delay (500); //Waiting for 500 ms
id_read = 0;//Reset the constant
therm_duty = 0; //Reset the constant
b1 = b2 = b3 = b4 = 0;//Reset the constant
}
}
}
However, I found that the LED light on the bridge circuit board was not on, which may have been damaged in the welding process. And the LED light on the slave circuit board continued to shine in the way I programmed it.

...


Here you can see them working from the serial port!

File Download


Group Assignment

IC2

Hello attiny44 bus

contact Me


Address: No.10, Kehua street, Wuhou District, Chengdu, Sichuan Province, China
TEL: (028) 85406538 (+86)18981085882
E-mail: linzihao@scuspark.com
QQ: 386866966