Hi there,
Through the assistance of various guides, I am currently writing the code for an Arduino to receive DMX data.
I am currently getting the error:
"Arduino: 1.6.12 (Mac OS X), Board: "Arduino/Genuino Uno"
/Users/macbookpro/Documents/Arduino/Draft_DMX_Receiving_code._3_errors./Draft_DMX_Receiving_code._3_errors..ino: In function 'void loop()':
/Users/macbookpro/Documents/Arduino/Draft_DMX_Receiving_code._3_errors./Draft_DMX_Receiving_code._3_errors..ino:139:35: warning: invalid conversion from 'volatile uint8_t* {aka volatile unsigned char*}' to 'uint8_t {aka unsigned char}' [-fpermissive]
#define val analogRead(DmxRxField)
^
/Users/macbookpro/Documents/Arduino/Draft_DMX_Receiving_code._3_errors./Draft_DMX_Receiving_code._3_errors..ino:140:19: note: in expansion of macro 'val'
analogWrite(13, val / 4)
^
In file included from sketch/Draft_DMX_Receiving_code._3_errors..ino.cpp:1:0:
/private/var/folders/75/h5d235_d0c5d1tmjhrjh5nbm0000gn/T/AppTranslocation/74DE9E7B-1066-465D-9E47-3064030D099A/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:136:5: note: initializing argument 1 of 'int analogRead(uint8_t)'
int analogRead(uint8_t);
^
HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_18'
sketch/Draft_DMX_Receiving_code._3_errors..ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences
The full code is:
/* pinout
pin0 - serial in
pin1
pin2
pin3~ REDPIN
pin4~ GREENPIN
pin5~ BLUEPIN
pin6~
pin7 - error2 - bad dmx (non dimmer data)
pin8 - error3 - last channel not recieved.
pin9~
pin10~
pin11~
pin12 - error1 - tooo much time between frames.
pin13 - dmx data output for demo.
apin0
apin1
apin2
apin3
apin4
apin5
pinout */
#define Dmxchannels 185
volatile uint8_t DmxRxField[Dmxchannels]; //array of 8 bit int DMX vals (raw)
volatile uint16_t DmxAddress; //start address (16 bit int)
enum States {IDLE, BREAK, STARTCODE, MYADDRESSES};
States gDmxState; //create a global variable.
//idle - sit at idle state
//break - break received. Expect Data .
//startcode - Start code received. Main Data frames Follow.
//myaddresses - we've started receieving data for my addresses.
//error1 is no new packet within time defined by the defualt timer.
boolean error1 = true;
int timer;
int defaulterror1time=300;
//error2 for bad DMX (non dimmer data)
boolean error2 = true;
//error3 is for last channel not recieved.
//it only is true if a new packet is recieved before the end of the last one.
//its implimented in two parts.
//serror3 is within the ISR, it's set to true at the begining of a packet,
//serror3 is set to false once the last frame expected is recieved.
boolean error3 = false;
boolean serror3 = false;
//in the break section of code, if it gets to a break and is still an error
//then that means that error3 has occoured.
void setup()
{
Serial.begin(250000);
gDmxState= IDLE;
DmxAddress = 1; // The desired DMX Start Adress
pinMode(13,OUTPUT); //added by me for an example.
timer=defaulterror1time;
pinMode(12,OUTPUT); //error 1 LED
pinMode(7,OUTPUT); //error 2 LED
pinMode(8,OUTPUT); //error 3 LED
}
ISR(USART_RX_vect) {
//this code/function is called whenever the harware UART recieves a low
//startbit (well it's called after the byte is recieved.)
// two byte counter - needed to count upto all 512 channel frames
static uint16_t DmxCounter;
uint8_t USARTstate= UCSR0A; //get state before data!
uint8_t DmxByte = UDR0; //get data
uint8_t DmxState = gDmxState; //just load once from SRAM to increase speed
if (USARTstate &(1<<FE0)) //check for break
{
//data has been recieved, the USART is enabled and it's
//low signal for more than 8 bits
// so an error has also been created - this is a Break.
gDmxState= BREAK;
DmxCounter = DmxAddress;
//dmx counter counts down untill it reaches the address
if(serror3==true) {error3=true;}
serror3 = true; //as we're at the start of a packet.
//lets set the error1 timer back to it's default and set it to
//false as DMX is imcomming
timer=defaulterror1time; error1=false;
}
else if (DmxState == BREAK)
{
if (DmxByte == 0) //normal start code detected
{gDmxState= STARTCODE; error2=false;}
else //non normal start code recieved eg: RDM packet.
//ignore the rest of the packet.
{ gDmxState= IDLE; error2=true;}
}
else if (DmxState == STARTCODE)
if (--DmxCounter == 0)
DmxRxField[DmxCounter]= DmxByte;
DmxCounter= 1;
if(Dmxchannels==1){gDmxState= IDLE;serror3 = false;}
else{gDmxState= MYADDRESSES;}
{
DmxRxField[DmxCounter++]= DmxByte;
if (DmxCounter >= Dmxchannels)
{
gDmxState= IDLE;
serror3 = false;
}
}
//end of ISR
}
void loop()
{
//error output status'.
if(error1==true){digitalWrite(12, HIGH);}else{digitalWrite(12, LOW);}
if(error2==true){digitalWrite(7, HIGH);}else{digitalWrite(7, LOW);}
if(error3==true){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);}
if(timer==0) {error1=true;}
else { timer--; }
delay(1);
if(DmxRxField[1]>1) {analogWrite(13, 255);}
else {analogWrite(13, 0);}
if(DmxRxField[2]>1) {analogWrite(14, 255);}
else {analogWrite(14, 0);}
{
#define val analogRead(DmxRxField)
analogWrite(13, val / 4)
;}
}
What am I doing wrong? i only have a very basic understanding of the coding language.
Thanks!!