In this assignment i decided to work the comunication between arduinos. In the example i made it with Arduino Uno, but i can make the same example with our own developed arduino that were made here in Fablab Lima by Cristian Cisneros.
The first part was to understand how the comunication between two arduinos works, everthing i learned from the tutorial of Satoshi Itaya.
This image explains that there are two things to comunicate SDA (clock to send sincronization) and SCL (used for sending data) the data will be sent to all slaves but only the slave that should receibe the data will answer a confirmation and will process the data. The most important thing here is to understand the process of comunication:
This steps i wrote on C language using the plattform of arduino, for this i had to include this:
This is the Master Programm
#include <avr/io.h> // this is for using IO registers ej DDR , PORTD etc.
#include <util/delay.h>
//initializer
void setup (){
DDRB= 0xff; // all Pin B is output mode
PORTB= 0x00; //all Pin B is low
TWSR= (1<<TWPS1)| (1<<TWPS0);
TWBR = 0xFF;
//This would be the same to write
// TWSR = 0b00000011;
// TWSR = Ox02;
}
// loop process
void loop (){
// start comunication
// send start signal
TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
// TWCR= Ob10100100;
while (!(TWCR&1 <<TWINT));
_delay_ms(1);
if ((TWSR & 0xf8) == 0x08){ /// mask
TWDR = 0b00000010; //set slave adress
TWCR = 0b10000100; // update flag
while (!(TWCR&1 <<TWINT));
_delay_ms(1);
if ((TWSR & 0xf8) == 0x18){
TWDR = 0b10101010; //send data
TWCR = 0b10000100; // update flag
while (!(TWCR&1 <<TWINT));
_delay_ms(1);
}
}
#include <avr/io.h>
#include <util/delay.h>void setup(){
DDRB= 0xff; // all Pin B is output mode
PORTB= 0x00; //all Pin B is low
//adress setting
TWAR = 0b00000010;
}void loop() {
TWCR = 0b11000100; //
_delay_ms(1);
if ((TWSR & 0xF8) == 0x60){ //check ack response
while(1){
TWCR = 0b11000100; //waiting for data
while (!(TWCR&1 <<TWINT));
if ((TWSR & 0xf8) == 0x80){ ///check the ack
char data = TWDR;
PORTB = data;
}
if ((TWSR & 0xf8) == 0xA0){ ///check the ack
break;
}
}
}
}
This is the data master and the slave adress signal on osciloscope:
To be show the process of comunication i put a LED:
I made this with Arduino uno but, that was because i was not finished my own arduino component, so after a few weeks I finished my assignment i built the fab arduinos.
Repeating the same process with this new arduino would be the same. So I discover that i can also create my own arduinos!! and are much more cheap. Unfortunatly the video using my own arduinos has a mistake and the arduinos are no more working.
This are two new arduinos, the first is fab io and the other is a local designed arduino. Fab io had many problems and the documentation is false in many photos, schematic and board are different on the documentation. The other arduino i used for final project and no more for networking because i did just one.