Before we begin you may want to peruse the Arduino website. The Wire library is described HERE and detailed HERE. When you finish those, let's dive in.
The first thing I did was run the master_reader and slave_sender examples. This was very easy. It sends hello from the slave to the master and displays it on the serial monitor.
Next I decided to make it transmit something useful. I made an I2C HC-SR04. The slave Arduino constantly takes distance measurements with the HC-SR04 sonar module. The master Arduino can then poll the slave whenever it wants to get the current distance measurement.
Wiring is the same as above. Make sure you use your pull-up resistors. I connected the trigger pin of the sonar to pin 7 and the echo to pin 8, but you could use any of them.
HERE is my code. Hopefully I will have time to rewrite the slave for the ATtiny in the future. That is the plan. Right after wireless communication, robot arm, computer vision..
Matthew
This comment has been removed by the author.
ReplyDelete