I am using the SoftwareSerial library with a 4d systems 4.3" screen
I have tried this on both the Arduino UNO and the Arduino Mega 2560 with the same result.
I have used the Visi Genie to create all of my interfaces.
The problem lies in the fact that I am getting 0 data transfer from the screen to arduino
mySerial.available()
is giving me 0 which will not allow any of the other code to run.
I have also used the following code.
///
/// @mainpage Arduino_RGB_Genie
/// @details Set colour from panel with red-green-blue sliders
/// @n
/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
///
/// @author Rei Vilo
/// @date Nov 13, 2012
/// @version 308
///
// Core library
#include "Arduino.h" // for Arduino 1.0
// Include application, user and local libraries
#include "SoftwareSerial.h"
// Define variables and constants
SoftwareSerial mySerial(2, 3);
#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11
#define READ_OBJ 0x00
#define WRITE_OBJ 0x01
#define REPORT_OBJ 0x05
#define REPORT_EVENT 0x07
const uint16_t buttonReset = 0x0600;
const uint16_t sliderRed = 0x0400;
const uint16_t sliderGreen = 0x0401;
const uint16_t sliderBlue = 0x0402;
uint8_t red, green, blue;
uint8_t command;
uint16_t object, value;
boolean flag;
uint8_t nacAck() {
delay(10);
while (!mySerial.available());
return mySerial.read(); // 0x06 or 0xd5
}
bool readMessage(uint8_t &command0, uint16_t &object0, uint16_t &value0) {
bool flag0 = false;
uint8_t buffer[6];
uint8_t checksum = 0x00;
uint8_t i=0;
if (mySerial.available()>0) {
buffer[i] = mySerial.read();
command0 = buffer[0];
i++;
checksum = command0;
if (command0==REPORT_EVENT) {
if (mySerial.available()>3) {
buffer[i] = mySerial.read();
checksum ^= buffer[i];
i++;
buffer[i] = mySerial.read();
checksum ^= buffer[i];
i++;
object0 = buffer[1]<<8 | buffer[2];
buffer[i] = mySerial.read();
checksum ^= buffer[i];
i++;
object0 = buffer[1]<<8 | buffer[2];
buffer[i] = mySerial.read();
checksum ^= buffer[i];
i++;
value0 = buffer[3]<<8 | buffer[4];
}
}
flag0 = (checksum==mySerial.read());
}
return flag0;
}
bool sendMessage(uint8_t command0, uint16_t object0, uint16_t value0) {
bool flag0 = false;
uint8_t buffer[6];
uint8_t checksum = 0x00;
uint8_t i=0;
buffer[i] = command0;
checksum = command0;
i++;
buffer[i] = object0 >>8;
checksum ^= buffer[i];
i++;
buffer[i] = object0 & 0xff;
checksum ^= buffer[i];
i++;
buffer[i] = value0 >>8;
checksum ^= buffer[i];
i++;
buffer[i] = value0 & 0xff;
checksum ^= buffer[i];
i++;
buffer[i] = checksum;
i++;
mySerial.write(buffer, i);
return (nacAck()==0x06);
}
void update() {
analogWrite(RED_PIN, red); // value for red channel
analogWrite(GREEN_PIN, green); // value for blue channel
analogWrite(BLUE_PIN, blue); // value for green channel
}
void reset() {
uint8_t a;
red = 0x7f;
green = 0x7f;
blue = 0x7f;
mySerial.flush();
a = sendMessage(WRITE_OBJ, sliderRed, red);
a = sendMessage(WRITE_OBJ, sliderGreen, green);
a = sendMessage(WRITE_OBJ, sliderBlue, blue);
update();
}
// Add setup code
void setup() {
delay(3000);
mySerial.begin(9600);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
reset();
update();
}
// Add loop code
void loop() {
if (readMessage(command, object, value)) {
if (command==0x07) {
switch (object) {
case buttonReset:
reset();
break;
case sliderRed:
red = value & 0xff;
update();
break;
case sliderGreen:
green = value & 0xff;
update();
break;
case sliderBlue:
blue = value & 0xff;
update();
break;
default:
break;
}
}
}
delay(100);
}
Any ideas???