Networking and communications

This assignment I connected my two boards designed in my Electronics design and Output assignment.

- First attempt with IC2 and Arduino boards

To understand the assignment, first I did one experience with two Arduinos Boards (one Master and other slave via I2C).

This tutorial helped me to understand that the

“I2C protocol involves two lines to send and receive data: a serial clock pin (SCL) Pin A5/Arduino Master board pulses at a regular interval, ‘as a timing’ and a serial data pin (SDA)/A4 over which data is sent between the two devices".

Then, I uploaded this code in the Master/Arduino board

import Part
#include < Wire.h >
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;
void loop() {
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  x++;
  delay(500);
            }


            	

And this code in Slave/Arduino board

import Part
#include < Wire.h >
void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  }

  void loop() {
    delay(100);
            }

    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()
    void receiveEvent(int howMany) {
    while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
      }
      int x = Wire.read();    // receive byte as an integer
      Serial.println(x);         // print the integer
    	}
            

I succeed in return the variable "x" from the Slave/Arduino board sending to Master/Arduino board to print it. This is my result

- Second attempt with my board (Electronic design) and my "minimal microcontroller board" (Output)

I worked with my two boards designed in my Output and Electronic design to do the network communication.

Reviewing Mario Fulllone and Silvia Pallazi assignments I realized that the library to network is the main problem when you program Attiny44 with Arduino IDE.

To do the Attiny 44 communication, (my two boards have Attiny´s 44) I had to upload the "TinywireM.h" and "TinywireS.h" libraries in the IDE. I used my Fab ISP to program my board but I did not succeed as below:

Errors "TinywireM.h" and "TinywireS.h" libraries

- Trying to correct uploading the Tiny libraries and old Arduino IDLE versions with no success

This step unfornately was not possible because when I tried to upload again the Tiny libraries, the Arduino IDE 1.6.4 version showed the "Already installed message" . Somewhere I read that Arduino version could be the problem, so I tried to install an old version, and you should do not do this, the TinyWire library was not recognized. by the Arduino 1.0

- Back to the fight with code and Tinylibraries with no success, again...

Using Arduino 1.6.4 version, I succeed uploading in the my master board the "USI_TWI_Master.h library " and the code below uploaded without errors.

.



#include < TinyWireM.h >
#include < USI_TWI_Master.h>
#include < SoftwareSerial.h>
SoftwareSerial mySerial(0,1); // RX, TX
int x = 0;

void setup() {
// Start the I2C Bus as Master
mySerial.begin(9600);
            }

void loop() {
  mySerial.begin(9); // transmit to device #9
  mySerial.write(x);              // sends x
  mySerial.end();    // stop transmitting
  x++; // Increment x
  if (x > '5') x = '0'; // `reset x once it gets 6

  delay(500);
            }

            

But...when upload the Slave board...



#include < TinyWireS.h>
#include < USI_TWI_Master.h>
#include < SoftwareSerial.h>
SoftwareSerial mySerial(0,1); // RX, TX
void setup() {
  mySerial.begin(8);                // join i2c bus with address #8
  mySerial.onReceive(receiveEvent); // register event
 mySerial.begin(9600);           // start serial for output
            }

void loop() {
delay(100);
            }

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
  void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
  char c = Wire.read(); // receive byte as a character
 mySerial.print(c);         // print the character
      }
int x = Wire.read();    // receive byte as an integer
mySerial.println(x);         // print the integer
      }


            

Then, the erros...


Arduino: 1.6.4 (Linux), Placa:"ATtiny24/44/84, ATtiny44, Internal 8 MHz"
Slave_Net_1_44_ok.ino: In function 'void setup()':
Slave_Net_1_44_ok:11: error: 'class SoftwareSerial' has no member named 'onReceive'
Slave_Net_1_44_ok.ino: In function 'void receiveEvent(int)':
Slave_Net_1_44_ok:22: error: 'Wire' was not declared in this scope
Slave_Net_1_44_ok:26: error: 'Wire' was not declared in this scope
'class SoftwareSerial' has no member named 'onReceive'
Este relatório deveria ter mais informações
"Mostrar saída verbosa durante a compilação"
habilitado em Arquivo > Preferências.

            

Researching, I read in one page that the I2C is very difficult with Attiny 44. Then I returned to the begin, uploading libraries.

-Testing with the others Tiny Master/Slave 44 Libraries

Talking with my tutor Kenzo, he suggested another Attiny libraries and I begin to work at the begining.

First, as my tutor suggested, I tested the examples from Arduino IDE folders . The errors happened as "Multiple libraries were found for TinyWireM.h" at my Arduino IDE

Then, I deleted all the Attiny (master and slave) libraries in the Arduino IDE going to library folders deleting one by one and leave only my tutor suggested, that was

Trying to compile another error happened begining with "USI_TWI_Master.cpp: In function 'void USI_TWI_Master_Initialise()': and I found Madeleine Abromowitz page explaining that the error is only that the IDE was not defined for the ATTinyX4. And that was correct ( my IDE was for Arduino) the error and the example compiled!

Finally, I worked with Jean Marie code changing the pins ( adequating to my boards) and it hopefully worked! I blinked my button board as a slave.

20170702_121527 from Alex Angelo on Vimeo.

Here is the Master.ino Arduino IDE file

Here is the Slave.ino Arduino IDE file