This is my make-through for the week's assignment. Lets Rock!
This week we've learned the different types of communications such as I2C, SPI, UART , SPI and at the end of the week we were asked to establish a communications between 2 boards using any communication so lets get started !
So this week's assignment requirements was to use 2 boards one as a master and the other as slave so i thought it would be great to use the ATTINY44 board as master and our atmega board as a slave.
After watching the videos i have downloaded the examples code and checked them out after that i needed to change some values to fit in my board's I/O Pins.
After checking our Atmega Pin out i have changed the values in the examples to my values that is shown in the board layout
Then i grabbed my attiny board and changed the switch pin in the examples code to my assigned switch in the board that i have done in week 3.
The whole assignment's idea is to use the attiny44 board as a master and the atmega board as a slave and use a communication protocol to send a message from master board to slave board using a specific ID the slave board receive this command if it meets the same ID and letter that is included in the slave board the LED must stop blinking if the switch in the master board is pressed.
For me i have used a UART communication with a specific ID for the slave board and unfortunately the attiny board does not support any communication protocol but we just use a library called " SoftwareSerial.h " which somehow simulates this communication protocol and the master board gets connected to the slave board by using addresses that is specified in both master and slave code...
After editing the code examples it is uploading and testing time!
For Atmega board i have checked the board layout to attach my ISP Pins to program it using USBasp and i did not do the same in the attiny board because it already has a ISP Header so i just plugged the USBasp directly
But the only difference here is in the code uploading in the atmega board we choose from the boards manager that we are using an arduino uno.
And if we are using an attiny board we need to choose the attiny board option in the boards option and specify the model and the clock frequency whether it is internal or external clock.
i have successfully uploaded the slave code in the slave board (atmega) but i have faced an error while uploading the master code saying that my board is not connected so i have checked the code and the port with wiring and everything but unfortunately still not working!
Problem: Failed to upload code in master board
Potential Solution: use another board till figuring out the problem.
Unfortunately i did not figure out the problem in the attiny so i just used my regular arduino uno board and the only change i did is to use the internal arduino's pin in the slave board so i just hooked up the slave board using USBasp and uploaded the code and done the same for the slave and connected the RX and TX , Ground Pins in both boards and it was working like a charm !
This time i wanted to establish a SPI communication between 2 arduino boards so i have used an arduino uno and our own atmega board, the 2 boards exchange 2 characters once the switch is pressed it sends character a to slave board then when slave board receives the character the internal led get turned off then when i leave the button the board sends another character to turn off the led so the role of the arduino uno is slave while the atmega is a master.
I didn't use more than 2 nodes so i haven't used any addressing methods i only connected the master (MOSI, MISO, SCK, SS) pins to the slave (MOSI, MISO, SCK, SS) pins and for the SPI communication i have used library that is called SPI .h .
To program the nodes was easy i just hooked up the USBasp header to the arduino uno ISP header then opened arduino IDE and uploaded the code, to upload the code to the atmega board i used the board layout that i have previously mentioned and hooked up the (MOSI, MISO, SCK, SS) pins and uploaded the code using programmer.
For the problems i did not face any issues through the wiring or coding.
the difference between attiny and atmega in programming is the core, if we are programming an arduino uno with 16mhz external clock we choose arduino uno from boards menu, if it is an attiny we should choose the right model then specify the type of clock whether it is internal or external then choose the right clock speed.
What I learned this week is...
This week we have learned the different types of communication protocols and how to establish a connection using each protocol and assign and IDs for each board if we are using several nodes that are connected with each others.
Utilize UART and I2C protocols to send messages between a master microcontroller and a slave microcontroller at defined address
Utilize SPI protocol to send messages between at least two microcontrollers interchangeably