HI,
I have a EasyCAT shield connected to an Arduino and I have had success in editing the TestEasyCAT example file, allowing me to send a simple on/off signal from a device connected to the Easycat to a camera connected to the Arduino.
Now I plan to remove the camera and attach a DMX shield to control a RGBW light.
I'm wondering if it is possible within my Arduino code to convert 4 analog signals to the 0-255 values needed to be send to the DMX light, if so how? Of if it is best to use digital?
Heres my code at the moment (sorry for any unnecessary bits - I wasn't sure what I could delete!)
//---- AB&T EasyCAT shield application example V.2_0 -------------------------------------------
#include "EasyCAT.h" // EasyCAT library to interface the LAN9252
#include <SPI.h> // SPI library
EasyCAT EASYCAT; // EasyCAT istantiation
// The constructor allow us to choose the pin used for the EasyCAT SPI chip select
// Without any parameter pin 9 will be used
// We can choose between:
// 8, 9, 10, A5, 6, 7
// On the EasyCAT board the SPI chip select is selected through a bank of jumpers
// (The EasyCAT board REV_A allows only pins 8, 9, 10 through 0 ohm resistors)
//EasyCAT EASYCAT(8); // example:
// pin 8 will be used as SPI chip select
// The chip select chosen by the firmware must match the setting on the board
//---- pins declaration ------------------------------------------------------------------------------
const int Ana0 = A0; // analog input 0
const int Ana1 = A1; // analog input 1
const int BitOut0 = A2; // digital output bit 0
const int BitOut1 = A3; // digital output bit 1
const int BitOut2 = A4; // digital output bit 2
const int BitOut3 = A5; // digital output bit 3
const int BitIn0 = 3; // digital input bit 0
const int BitIn1 = 5; // digital input bit 1
const int BitIn2 = 6; // digital input bit 2
const int BitIn3 = 7; // digital input bit 3
//---- global variables ---------------------------------------------------------------------------
UWORD ContaUp; // used for sawthoot test generation
UWORD ContaDown; //
unsigned long Millis = 0;
unsigned long PreviousMillis = 0;
unsigned long PreviousSaw = 0;
unsigned long PreviousCycle = 0;
//---- setup ---------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // serial line initialization
//(used only for debug)
Serial.print ("\nEasyCAT - Generic EtherCAT slave\n"); // print the banner
pinMode(BitOut0, OUTPUT); // digital output pins setting
pinMode(BitOut1, OUTPUT); //
pinMode(BitOut2, OUTPUT); //
pinMode(BitOut3, OUTPUT); //
pinMode(BitIn0, INPUT_PULLUP); // digital input pins setting
pinMode(BitIn1, INPUT_PULLUP); //
pinMode(BitIn2, INPUT_PULLUP); //
pinMode(BitIn3, INPUT_PULLUP); //
ContaUp.Word = 0x0000; //
ContaDown.Word = 0x0000; //
//---- initialize the EasyCAT board -----
if (EASYCAT.Init() == true) // initialization
{ // succesfully completed
Serial.print ("initialized"); //
} //
else // initialization failed
{ // the EasyCAT board was not recognized
Serial.print ("initialization failed"); //
// The most common reason is that the SPI
// chip select choosen on the board doesn't
// match the one choosen by the firmware
pinMode(13, OUTPUT); // stay in loop for ever
// with the Arduino led blinking
while(1) //
{ //
digitalWrite (13, LOW); //
delay(500); //
digitalWrite (13, HIGH); //
delay(500); //
} //
}
PreviousMillis = millis();
}
//---- main loop ----------------------------------------------------------------------------------------
void loop() // In the main loop we must call ciclically the
{ // EasyCAT task and our application
//
// This allows the bidirectional exachange of the data
// between the EtherCAT master and our application
//
// The EasyCAT cycle and the Master cycle are asynchronous
//
EASYCAT.MainTask(); // execute the EasyCAT task
Application(); // user applications
}
//---- user application ------------------------------------------------------------------------------
void Application ()
{
UWORD Analog0;
UWORD Analog1;
Millis = millis(); // As an example for this application
if (Millis - PreviousMillis >= 10) // we choose a cycle time of 10 mS
{ //
PreviousMillis = Millis; //
Analog0.Word = analogRead(Ana0); // read analog input 0
Analog0.Word >>= 2; // normalize it on 8 bits
Serial.println(Analog0.Byte[0]);
Analog1.Word = analogRead(Ana1); // read analog input 1
Analog1.Word >>= 2; // normalize it on 8 bits
Serial.println(Analog1.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[0]);
Serial.println(EASYCAT.BufferOut.Byte[1]);
Serial.println(EASYCAT.BufferOut.Byte[1]);
Serial.println(EASYCAT.BufferOut.Byte[1]);
if (EASYCAT.BufferOut.Byte[0]) // the four output bits are mapped to the
digitalWrite (BitOut0, HIGH);
else
digitalWrite (BitOut0, LOW);
}
}