I2C communication between arduino and uvga

hi,

i have connect a touch screen resistive on my mega, and i want to send position value to uvga but its not work i don't know anymore the protocol I2C can you explain me why the code doesn't work?

#include "Wire.h"
int xVal;
int yVal;
void setup()
{
  Wire.begin();
}

int readX() // returns the value of the touch screen's X-axis

{
int xr=0;
pinMode(A1, OUTPUT);   
pinMode(A2, INPUT);    
pinMode(A3, OUTPUT);   
digitalWrite(A1, HIGH); 
digitalWrite(A2, LOW);  
delay(5); 
xr=analogRead(2); 

}

int readY() 

{
int yr=0;
pinMode(A2, OUTPUT);   
pinMode(A3, INPUT);    
pinMode(A4, OUTPUT);    
digitalWrite(A2, LOW);
digitalWrite(A4, HIGH); 
delay(5); 
yr=analogRead(3); 
return yr;

}

void loop()
{
  Wire.send(xVal);
  Wire.send(yVal);
}

thanks.

can you explain me why the code doesn't work?

Not unless you define "doesn't work". That code does something. You expect it to do something. What either of those things is, though, is a mystery.

What does the code do? What do you expect it to do?

A picture of your Arduino with stuff attached, and a schematic, would be helpful, too.

You never read anything from the Wire instance. Why not?

An I2C device would be connected to digital pins 20 and 21. Is yours? Why are you diddling with the analog pins (as digital pins) in readX() and readY()? What is connected to analog pins 2 and 3? Why?

Does you space key not work?

xr=analogRead(2); 
yr=analogRead(3);

Why doesn't readX() have a return statement?

on the arduino pins 20 (SDA) connect to the uvga pin j1-10, pin 21 (SCL) connect to j1-9.

for the touch screen pin A1 to A4 the 4 wire of the resistive touch pannel. on A2 signal for the postion x, on A3 signal for the position y.

with the rx/tx communication will work but very slow for my future project.

on the arduino pins 20 (SDA) connect to the uvga pin j1-10, pin 21 (SCL) connect to j1-9.

Are we supposed to guess that that is OK? A link to the device you are trying to talk to would be useful?

with the rx/tx communication will work but very slow for my future project.

I doubt that it is serial communication that is the bottleneck. Baud rate, maybe, but not that fact that communication is serial vs. I2C. Hard to say, though, without knowing what you are trying to communicate with.

here the uvga: http://www.4dsystems.com.au/prod.php?id=149

for the wiring i'm sure.

The only mention of I2C in the data sheet that I see ways that the uvga is an I2C master. You are trying to treat it as a slave. That is not going to work.

you know how to work with the arduino in slave and uvga in master?

you know how to work with the arduino in slave and uvga in master?

No clue. The Arduino would need to register as a slave with some address, and register a callback for use when the master sent a request/command/data.

The uvga would then send messages to the slave at that address. How it would do that, though, I do not know, nor do I know what those messages would look like or what the reply would need to be, if any.

What was your problem with serial communication with the uvga? It supports baud rates faster than the Arduino does.

with serial communication its very slow

because i want to make an dashboard for car with some gauge and menu. have a look here with my gauge for boos pressure: jauge uvga - YouTube

the needle moove very slowly

the needle moove very slowly

Clearly a code problem, then. Posting some code might be useful.

arduino code for the gauge:

void setup(){
  Serial2.begin(115200);
 
}
void loop()
{


unsigned int new_turbo = analogRead(3);
unsigned int ancien_turbo=3;
int pression;
pression=map(new_turbo,0,1024,0,30);

if(new_turbo != ancien_turbo)
  {
  Serial2.print(pression,BYTE);
  ancien_turbo=new_turbo;
delay(5);
  }
 

  }

you want the 4dgl code?

Every time the new and old readings are different, you have a delay. Why?

Having a non-static local variable in the loop() function means that it gets reset to 3 on every pass through loop, so every time you do not read 3 from the analog pin (no idea what is connected to it), you write to the uvga and have a 5 millisecond delay. I'm guessing that 99% of the time, the Arduino is doing nothing but waiting.

in this code on A3 i connect a map sensor with linear signal 0-5v

we have say to me on the french forum to put a delay and an unsigned int to 3 for the if function.

What you should have is:

byte old_value = 0;

void loop()
{
   unsigned int turbo = analogRead(3);
   byte new_value = map(turbo, 0, 1024, 0, 30);
   if(new_value != old_value)
   {
      Serial2.write(new_value);
   }
   old_value = new_value;
}

Writing to the uvga only when the value changes is a good idea. Delaying after doing so is not.

Note that the old and new values are based on the mapped values, not those read from the map sensor.

The upper limit of the from range, by the way, should be 1023, not 1024.

ok, i try this tomorrow.

you can explain me how to send multiple data by serial?

you can explain me how to send multiple data by serial?

Serial.print("This");
Serial.print("is");
Serial.print("how");

if i do this i recover just the first value on the uvga

if i do this i recover just the first value on the uvga

What is that value? "This" or "Thisishow"?

when i say value i want to say numeric value, i don't try char ascii