design and build a wired and/or wireless network connecting at least two processors
Have I...?
Described my design and fabrication process using words/images/screenshots? YES
Explained the programming process/es I used? YES
Outlined problems and how I fixed them? YES
Included original design files and code? YES
I2C Communication
As first weekly work I decided to try the I2C Communication.
The Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips. Like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device. Like Asynchronous Serial Interfaces (such as RS-232 or UARTs), it only requires two signal wires to exchange information.Via
In I2C communication it's possible to create a communication between at least two components, a master and a slave. As requested by the assignment, I used two of mine board: the board I made for Input Devices (with an ATtiny45) and the board I made for Electronics Design (with an ATtiny44). I decided to make the ATtiny44 one the master reader board and the ATtiny45 one the slave sender one. It needs basically two communication channels:
the SDA (Serial Data)
the SCL (Serial Clock)
Looking again at both datasheets, I could see where this kind of pins are located.
My Master has ATtiny 44 with an external 20MHz clock. Here I used TinyWireM library, modified for working with "Tiny" microcontrollers and included in Arduino IDE. Here is its official GitHub page.
/* --MASTER CODE -- */
#include <SoftwareSerial.h>
#include <TinyWireM.h>
#include <USI_TWI_Master.h>
SoftwareSerial darioSerial(0,1);
void setup(){
darioSerial.begin(9600);
TinyWireM.begin();
delay (300);
}
void loop(){
darioSerial.println("Hey I want to communicate");
TinyWireM.requestFrom(8,1);
while (TinyWireM.available()) {
int m = TinyWireM.receive(); //m is for "message"
darioSerial.println(m);
}
delay (600);
}
SLAVE CODE
My slave has an ATtiny45 with internal 8MHz clock. For slave code I used TinyWireS, as suggested by This tutorial. This library isn't included in Arduino IDE by default, so I had to add it downloading by its GitHub Page.
I flashed codes to my boards, I connected 4 pins as I explained before and I connected the master to my PC using an FTDI cable. I expected that my master send "Hey I want to communicate" and the slave "0". And infact this is the result:
Bluetooth Communication
I also tried to use a Bluetooth module to send wireless data to my laptop. That could be useful for my Final Project. As first thing, I tried to configure my HC-05 Bluetooth module for being seen by my laptop or smartphone, in order to understand better the right process to set it as well. I followed This useful tutorial, that helped me to enter in AT Command Mode and send command and settings via serial port using an Arduino Uno board.
According with the tutorial linked before, I upload the following sketch in a Arduino Uno board:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
BTSerial.write(Serial.read());
}
And connected the BT module to the board using this wiring layout:
RX Bluetooth to pin 11 (Tx)
TX Bluetooth to pin 10 (Rx)
GND Bluetooth to GND
VCC Bluetooth to 5V
EN(enable) Bluetooth to pin 9
After that I opened Arduino IDE serial monitor with 9600 baud rate and Both (NL & CR). But I had some problem during this phase because I could not send the commands: in fact if I tried to write AT, I didn't receive any answer from the serial monitor.
The complete list of AT commands is available HERE
After seeing again the tutorial, I understood that for entering in AT Command Mode, I had to press the little button on the bluetooth module and than connect the Arduino to my laptop. The feedback I had to receive was a 2-second delay of the red LED on the module. You can see the different delay between normal communication mode and AT command mode.
Than I opened again the serial monitor and, after verifying the right connection typing AT and receiving OK as answer, I setted the module with these parameters:
AT+NAME=Water0
AT+PSWD=1234
AT+UART=38400,1,2
So I disconnected e re-connected the Arduino for switching to normal communication mode in order to verify if the module would be properly recognized by my laptop and my smartphone. And this is the result:
So I tried to change the code. I made one that could read data coming the water flow connected to pin 2 and print in serial monitor via bluetooth. As you can see, in this passage I used my own board instead of Arduino Uno. I have described the board used in the following paragraph. The code I used is:
volatile int NbTopsFan;
int calc;
int sensor = 2; // pin connected to the sensor
void rpm()
{
NbTopsFan++;
}
void setup() {
pinMode(sensor, INPUT);
Serial.begin(38400);
attachInterrupt(0, rpm, RISING);
}
void loop() {
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay(1000);
cli(); //disable interrupts
calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
Serial.print(calc, DEC);
Serial.print(" L/hour\r\n");
}
I obviusly connected Bluetooth's RX to Arduino's TX and vice versa. I also connected water flow sensor to GND, VCC and pin 2. So I connected my laptop to bluetooth module Water0 with 1234 as password, I launched the Terminal app and I wrote screen /dev/cu.Water0-DevB to open a serial communication via this serial port (the bluetooth one) and this is the result:
And here a video to show the good result I obtained:
Board
As I said before, I designed a new board to be used also for Previous Week. I have also thought of it to be used for my Final Project, inserting a voltage regulator to reduce the current from 12 to 5V, a predisposition for external power supply and, of course, 4 pins for bluetooth communication (TX, RX, VCC and GND).