Assignment:


I2C - Jalap-ino(master), Luizino(Slave01) Mini-ProATMEGA328(Slave02):

Both Jalap-ino and Luizino microcontrollers with ATMEGA32U4.
Now, after Jalapino received his brand new shell, he's looking fancy, and for this reason he got the title of Master.
Jalapino was the 2nd ATMEGA32U4 board I made, Luizino was the first and for Jalapino I added more pins to it. These
pins are, among them, SDA & SCL. So I had to hack Luizino, soldering 2 pins + wires to it. Didn't look too good but it does its job. That doesn't matter, Jalapino got the looks.




Took me some time (the whole weekend) to get a hang of I2C. I used "wire.h" library in Arduino IDE.
What it does is to, via the Master, sends characters to the slaves. I programmed number 1 and 2 to be (respectively) turn on a LED and turn off the same LED on Slave 01. Numbers 3 and 4 will do the same, but to slave 02.
Once the code is uploaded, I open the Serial Monitor of the IDE and there I type the characters.
On the ATMEGA32U4 (Jalapino and Luizino), the pins to be used for i2c are the pin 3 as SCL and pin 2 as SDA.
For the MiniPro ATMEGA328, pin A5 is SCL and A4 is SDA.



I used pull up resistors as suggested in the tutorial I followed.
Important is that all GNDs (Grounds) from all the boards must be connected, and all VCCs (5V) also, via the pull ups.
There is a tutorial explaining it with all detais in here:

And this is the video of my result:



-Since the code is not too long, I'm posting it here:

//i2c JalapinoMaster code (to Luizino and ArduinoMiniProVersion)
//Luiz Henrique Heins Bueno - 16/05/216
#include
void setup() {
Serial.begin(9600);
Wire.begin();}
void loop() {
while(Serial.available()){
char c = Serial.read();
if(c == '1')
{ Wire.beginTransmission(5);
Wire.write('H');
Wire.endTransmission();
digitalWrite(13, HIGH);}

else if(c == '2')
{Wire.beginTransmission(5);
Wire.write('L');
Wire.endTransmission();
digitalWrite(13, LOW);}

if(c == '3')
{ Wire.beginTransmission(6);
Wire.write('H');
Wire.endTransmission();
digitalWrite(13, HIGH);}

else if(c == '4')
{Wire.beginTransmission(6);
Wire.write('L');
Wire.endTransmission();
digitalWrite(13, LOW);
}}}


Well, It's longer than I expected so I'm putting links here:

Files:

Arduino IDE coding:
-i2c Jalapino -> Luizino + MiniPro
Inside of this folder I also added a i2c Scanner code where you can test on your master board what addresses it is connected to.

In this week I learned how to connect microcontroller boards with i2c.
Many things went wrong until I understood what exactly and how to make them communicate.
I'm ready to do something bigger than making LEDs blink now.