Hello community of arduino, I am working on a project to measure voltage and frequency, I have 2 arduinos connected by I2C to each other, with one I control the screen and with the other measured frequency, at the moment I have only managed to measure frequency using a detector zero crossing "H11AA1", and I show it by the arduino ide serial monitor, the question is that I want to use that frequency value to show it on a Touch screen 320x240qvt, which I am controlling with another arduino MEGA that is the master of the system, and I send the data of the arduino SLAVE (with which I am measuring frequency) to the teacher, but I can not print the correct value on the screen, but I print values between 0 and 255, I have been investigating how send whole data by I2C protocol between arduino, but I can not make it work and data appear as I see them on the serial monitor, in advance thank you very much for reading me and if anyone can help me I would be very grateful to that person.
I attach the image in which the code on the left is the mestro and the one on the right is the slave:
https://1drv.ms/u/s!AoWVYNNzZXkmtDsu3jJPqm3TvNj7
Master arduino code:
#include <UTFT.h> // UTFT library to draw the screen
#include <URTouch.h> // Library for the Touch
#include <Wire.h> // Library for I2C Communication
extern uint8_t BigFont [];
UTFT myGLCD (ILI9341_16,38,39,40,41); // Declare the controller of our screen
int frequency = 0;
void setup () {
myGLCD.InitLCD ();
myGLCD.clrScr ();
myGLCD.setFont (BigFont);
myGLCD.fillScr (VGA_WHITE);
Wire.begin (1);
}
void loop () {
Wire.requestFrom (1,2);
while (Wire.available ()) {
frequency = int (Wire.read ()); // We transform the byte type to int
myGLCD.setColor (VGA_BLACK);
myGLCD.setBackColor (VGA_WHITE);
myGLCD.print ("FREQUENCY:", 10, 140, 0);
myGLCD.setColor (VGA_RED);
myGLCD.printNumF (frequency, 1, 190, 140);
myGLCD.print ("Hz", 270, 140, 0);
}
}
Code of the slave arduino the one that measures frequency:
#include <Wire.h>
int counter = 0;
void setup () {
Wire.begin (1);
Serial.begin (9600); // we initiate serial communication
pinMode (2, INPUT);
attachInterrupt (0, period, RISING);
Wire.onRequest (requestEvent);
}
void loop () {
delay (480);
Serial.println (counter);
counter = 0;
}
void requestEvent () {
Wire.write (counter);
}
void period () {
counter ++;
}
link of the video of how the data appear on the Touch screen:
[Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.[/ url]](https://1drv.ms/v/s! AoWVYNNzZXkmtDzDD5raXg6nEY1n)