Analog Readout to custom UDP String

Hello
I want to build a controller with several Faders, Buttons, etc. etc.
Now I’m a little bit stuck with programming and i’m not that genius that i could solve it…

In my file i first read out the faders (analog 1-8), then map them up to a 16Bit Value (receiving device accepts only 16 Bit). And then arduino should send via the ethernet shield as following:

“CS 1 CR”

How can i do that? I’m sure i did something weird…

well, here’s the monster

#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>

// MAC und IP Setup
byte mac = {
0x90, 0xA2, 0xDA, 0x0F, 0x1E, 0x8D };
IPAddress ip(192, 168, 1, 210);

// UDP Listen Port 48631 for Composer H/W, 48630 for SYM Designer H/W
unsigned int localPort = 48631;

// Remote Client Setup
IPAddress destinationIP (192, 168, 1, 201);
unsigned int destinationPort = 48631;

// Naming Inputs
const int Fader1 = A0;
const int Fader2 = A1;
const int Fader3 = A2;
const int Fader4 = A3;
const int Fader5 = A4;
const int Fader6 = A5;
const int Fader7 = A6;
const int Fader8 = A7;

const int Button1 = 0;
const int Button2 = 1;
const int Button3 = 2;
const int Button4 = 3;
const int Button5 = 5;
const int Button6 = 6;
const int Button7 = 7;
const int Button8 = 8;

const int LED1 = 9; //LED 2-8 May only be used with Ardunio Mega => on Uno Pins 10-13 and 4 will be needed for Ethernet Shield
const int LED2 = 11; //On Mega Pin 4, 10 and 50-52 will be needed for Ethernet Shield
const int LED3 = 12;
const int LED4 = 13;
const int LED5 = 14;
const int LED6 = 15;
const int LED7 = 16;
const int LED8 = 17;

// Naming S Values
int FV1 = 0;
int FV2 = 0;
int FV3 = 0;
int FV4 = 0;
int FV5 = 0;
int FV6 = 0;
int FV7 = 0;
int FV8 = 0;

int BV1 = 0;
int BV2 = 0;
int BV3 = 0;
int BV4 = 0;
int BV5 = 0;
int BV6 = 0;
int BV7 = 0;
int BV8 = 0;

int LV1 = 0;
int LV2 = 0;
int LV3 = 0;
int LV4 = 0;
int LV5 = 0;
int LV6 = 0;
int LV7 = 0;
int LV8 = 0;

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer = “acknowledged”; // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);

// Configuring digital I/O
pinMode (Button1, INPUT);
pinMode (Button2, INPUT);
pinMode (Button3, INPUT);
pinMode (Button4, INPUT);
pinMode (Button5, INPUT);
pinMode (Button6, INPUT);
pinMode (Button7, INPUT);
pinMode (Button8, INPUT);

pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
pinMode (LED7, OUTPUT);
pinMode (LED8, OUTPUT);

}

void loop() {

// Read values
FV1 = analogRead (Fader1);
FV2 = analogRead (Fader2);
FV3 = analogRead (Fader3);
FV4 = analogRead (Fader4);
FV5 = analogRead (Fader5);
FV6 = analogRead (Fader6);
FV7 = analogRead (Fader7);
FV8 = analogRead (Fader8);

// Upscale from 10 Bit to 16 Bit
FV1 = map (FV1, 0, 1023, 0, 65535);
FV2 = map (FV2, 0, 1023, 0, 65535);
FV3 = map (FV3, 0, 1023, 0, 65535);
FV4 = map (FV4, 0, 1023, 0, 65535);
FV5 = map (FV5, 0, 1023, 0, 65535);
FV6 = map (FV6, 0, 1023, 0, 65535);
FV7 = map (FV7, 0, 1023, 0, 65535);
FV8 = map (FV8, 0, 1023, 0, 65535);

Serial.print(FV1);
Serial.print("\t");
// send Data to the IP address and port defined above
Udp.beginPacket(destinationIP, destinationPort);
Udp.write(“CS <”);
Udp.write(FV1);
Udp.write(">");
Udp.endPacket();

delay(10);

}

I'd suggest that you start with a much simpler sketch that just sends a single command to one fader, without reading any values. It looks to me as though the format required may not be what you expect. I assume for example that the CR field is actually a carriage return (ascii 13). I also wonder whether those angle brackets are required, or just part of the description of the format. Do you have a link to a description of it?

hi there Control Protocol Reference is right there... http://www.symetrix.co/?wpdmdl=22

i guessed, that it's a heavy lifting project... i also did the beginner examples and really like to come into arduino... could you suggest me some literature according arduino and ethernet? i sniffed on udp with wireshark and i know that my arduino is giving something out.... but i don't know how exceptors are created. and the only programm language i know is php and even this is 6 or 7 years ago. would be great if someone could give me a hint.

thanks

As an example to see if you can make controller one do something, try:

    Udp.beginPacket(destinationIP, destinationPort);
    Udp.write("CS 1 32000\r");
    Udp.endPacket();

hello. this string command works fine.

ok. i'ts going on... i see my final problem (until i get to the next step ;)) is, that i now have "long" formatted variables and i need to send via the Udp.write() command which accepts only "char". how could i convert them? maybe it would also help to get the Variable FV1 into some "" without writing plain text. I've got in mind, that there was something like a "print" function in php which convertet Variables to plain text for transmitting them....

Udp.write(FV)

maybe someone unterstands my freakish description :)

Take a look at sprintf. It will let you produce the string you want.

i can't find this expression in the reference. In fact, I "just" need to convert the "long" format to a transmittable format for Udp.write which (as the reference says) would be char.

thanks a lot for getting me to the point now :)

oh, i've just seen on another post, that they've used Udp.print(). Maybe that could work….. or has anyone objections to this and would propose the way via sprintf? and why? i try to understand…. :)

s

udp.print is probably a perfectly good way to do it.

sprintf is a standard C function, not arduino specific, so it does not appear in the reference. Google should find it for you, as will wikipedia.

ok thanks. i'll test it at home.

to take the next step…. what could be the best way to go the other way round? let's say, an udp message in the same format will be received by the arduino (as example: CC 1 65536 \r). Now this string should be interpreted from arduino as digitalWrite(LED1, FULL);

Controller Channel 1 = LED1 and lets say 0-32500 is = Led LOW and 32501-65536 = Led High