Hi there,
I am trying to connect an arduino to a 4D display using the I2C bus because the serial port is in use. I want the arduino to collect analog sensor data and store that data until the 4D display is ready to request it.
I have been trying every combination that i can think off, looking at the reference manuals of both devices and the best i can get is getting the 4D device to request a string from the arduino and the arduino to send it.
I can't get it to send an integer, and i can't get it to send multiple sensor values.
below is the working code:
Arduino:
#include <Wire.h>
String data = "test";
void setup()
{
Wire.begin(4); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
}
void loop()
{
}
void requestEvent()
{
Wire.write(data.c_str());
}
4DGL code:
#platform "uVGA-III"
var buffer[4];
func main()
I2C_Open(I2C_FAST);
repeat
I2C_Idle();
I2C_Start(); // Generate Start condition
I2C_Write(0x09); // send slave address, R/W bit is 1
I2C_Idle();
I2C_Gets(buffer,4);
I2C_Nack(); // finished reading, send Not Ack
I2C_Stop(); // finished with bus
print("\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n","\n");
print("received: ",[STR]buffer);
gfx_Cls(); // clear screen and do it forever
forever
endfunc
does anyone know how i could do this? because the Picasso chip on the 4D device doesn't have any analog inputs, i need effectively an analog to I2C device, but i want to do this with the arduino because then i can do some preprocessing on the sensor data and free the screen up for just refreshing.
any help would be great thanks!