For this week assignment we had to setup up a network between at least two microprocessors we have built ourselfs - so I made at first a second microprocessor board. I going to do at first a wired communication through I2C because this is one of the most basic connection and realistic seen it is the right order to do this first. If I have enough time I will try to do also a wifi connection using the ESP8266-12F. Despite the fact that this little modul has on its own the capability the be used without any external microprocessor because of its builtin functionality - Neil asked as not to do so - more to use it as an ordinary extension for our own boards.
So I had to made also this little ESP board with the required pinouts and also the voltage regulation from 5V to 3.3V.
I like the idea of modularity, to have a separate modul for each task - that would make any changes or repairs easier and hasslefree, I believe.
#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("Communication works!"); // sends five bytes
Wire.write("1.."); // sends one byte
Wire.write("2..");
Wire.write("3..");
Wire.endTransmission(); // stop transmitting
x++; //increasing x by 1, counting up
delay(500); // time delay of a half second
}
#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
}