i already did the communications part to do the connexion between the inputs board and the android smart-phone via blue-tooth also in the outputs assignment week i mention that i wanted to control the solid state relay via the blue-tooth and a smart-phone for this week assignment specially dedicated to networking and communications i want to test the outputs board using a wired serial port sending commands from the pc. i want to control the state of the light bulb via bletooth using the smart-phone and a blue-tooth terminal app. first i have to describe how the communication works the communication is based in the UART protocol that uses 3 wires to communicate the tx, rx and the ground. most of the arduino boars already have the serial pins and there is a library to easily use the serial ports to communicate, also a lot of modules use the uart serial protocol to communicate, one of this modules is the blue-tooth module that converts data strings send from the microcontroller to the android app and in the inverse way via blue-tooth. to connect two devices we have to wire the port pins crossed so the tx pin from one device connects to the rx pin of the other both having a common ground. the attiny don't have the serial port pins so we have to configure them by the program using the mySerial library as an example i will show you the case of the inputs board that uses 2 and 3 port pins to communicate with the bluetooth module here is an example of the code configuring the 2 adn 3 pins as a virtual serial port for the inputs board here the 2 and 3 port pins will be the tx and rx of the port mySerial.begin(9600); will set the baud rate that is the communication speed that the micro-controller will speak, we have to configure all the devices with the same baud rate so they can understand to each other mySerial.read(); will read the serial port and save the data it receives mySerial.print(); will write to the serial port the variable value that we put in the brackets and if it is between " " it will write the string as it is inside the "" to test the outputs board i will use the usb to serial adapter to send the commands i will use termite software that let us select the com port where is connected the serial adapter, the baud rate and we can easily write commands in it you can download the termite sofware clicking here i have to change the program that the outputs board have to add the communication and the cases that will switch on and off the light depending of the data the board revive trough the serial porT i will use cases defined by the number 1 and 2 so if i send a 1 from the pc to the board the lamp will turn on and if i send a 2 the lamp will turn off this is the code that read the virtual serial port in the board wired to the 2 and 3 micro controller pins and send a signal to turn on and off the lap depending of the number received #include <SoftwareSerial.h> SoftwareSerial mySerial(0,1); char c; void setup() { mySerial.begin(9600); mySerial.println("conected"); pinMode(9, OUTPUT); } void loop() { if (mySerial.available()) { c=mySerial.read(); switch(c) { case'1': mySerial.println("ON"); digitalWrite(10, HIGH ); break; case'0': mySerial.println("OFF"); analogWrite(10, LOW); break; } } } i will connect the board to the serial to usb adapter to test the connexion program and function using the termite terminal. i found problems using the virtual serial port in the atiny2313 because of the Cristal oscillator so i re-design the board to work with and attiny 44a and i use the internal clock reducing the board size and components.
after redesigning the board and connecting the bluetooth this was the final result using the changing the serial to usb adapter by a blue-tooth module we can activate the lamp using our smartphone as a remote control. you can download a rar file with all the board design files with the new corrections and the arduino program clicking here i also want to control my final project using a blue-tooth and an android app so i invite you to go to the final project page to see the progress. final project page
slave reciver code #include "TinyWireS.h" #define I2C_SLAVE_ADDR 0x1 void setup() { pinMode(0,OUTPUT); TinyWireS.begin(I2C_SLAVE_ADDR); } void loop() { byte byteRcvd = 2; if (TinyWireS.available()) { byteRcvd = TinyWireS.receive(); //fwd if (byteRcvd == 1) { digitalWrite(0,1); delay(10); } //bwd if (byteRcvd == 0) { digitalWrite(0,0); delay(10); } } }
ABOUT ME
Design and build a wired &/or wireless network connecting at least two processors you can review the inputs assignment clicking here you can review the outputs assignment clicking here to test other kind of connexion i will use the wire library to connect one new board that will serve as a master and the board that i did for electronics design assignment that will work as a slave board i will add the files and pictures of the new master board you can find the files in a masterboard rar file clicking here in the next part i will add the two arduino codes for each board you an download the .rar file with the codes clicking here this is how the boards work
ASSIGNMENTS
week fifteen networking and communications
FINAL PROJECT

 

master writer code #include <Wire.h> int buttonState = A2; void setup() { pinMode(A2, INPUT); Wire.begin(); } void loop() { if (digitalRead(A2) == 1) { Wire.beginTransmission(0x1); Wire.write(1); Wire.endTransmission(); } if (digitalRead(A2) == 0) { Wire.beginTransmission(0x1); Wire.write(0); Wire.endTransmission(); } delay(10); }
CONTACT

 

Carlos Pérez Ramírez