Jump to content

Sleight

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. EDIT* Sorry, I somehow posted this in the Libraries section. Not sure how I did that. If there is a MOD available, please kindly move this into the appropriate section. Thank you. Hello Folks, I've had a TM4C123G LaunchPad microcontroller laying around for a few years since I had to purchase it for an introductory college course. I've moved into the land of Vixen Christmas light sequencing and realized I could use this little controller with its relays for a few light strands. However, I can't figure out how to get this device to speak with Vixen via serial. I used code from an Arduino forum that I thought would work, but it won't read the serial header that vixen sends (or at least I think that's what is wrong). I'm starting to get frustrated with this device and am wondering if it should just go out with the bathwater. I don't understand the topic well enough to differentiate between this device and an arduino, so I don't recognize code differences that are incompatible. Any help would be appreciated. This is the code and the error at the bottom. // *** diychristmas.org free software so long as this line remains in sketch! // Basically Vixen "generic" serial mechanical relay sketch // - Setup a generic serial controller to use this sketch // - Uses digitalWrite as this outputs LOW or HIGH no pwm values // - This is what is needed for a mechanical relay // Hookup the relay in order of channel definition // Define as many as you need // put channels (pins) in an array so we can use looping structures to control int channels[] = {27}; // There were more listed in the original code, but I only have one relay on pin 27. // Vixen information // speed for the com port for talking with player const long SERIAL_COM_SPEED = 115200L; // Generic Serial controller config - must be present, must match controller setup int CONTROLLER_HEADER[3] = {33, 34, 35}; // This is character !"# (hard to replicate in sequencer) // Relays // - most mechanical relays turn on when pin is low, off on high const int ON = LOW; const int OFF = HIGH; // these are program variables we need to use in multiple places const int SIZE_OF_HEADER = sizeof(CONTROLLER_HEADER) / sizeof(int); // no need to change const int CHANNEL_COUNT = sizeof(channels) / sizeof(int); // no need to change int buffer[CHANNEL_COUNT]; // no need to change going to hold relay output values void setup() { Serial.begin(SERIAL_COM_SPEED); // set the channel pins to output mode for (int channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) { pinMode(channels[channelIndex], OUTPUT); } turnLightsOff(); powerOnSelfTest(); // watch your lights to make sure they are all going on in order } void loop() { waitForControllerHeader(CONTROLLER_HEADER); readSequenceData(); outputToLights(); } void turnLightsOff() { //turn them all off for (int channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) { digitalWrite(channels[channelIndex], OFF); } } void outputToLights() { for (int channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) { // we should only be seeing 255 and 0 but in case someone tried a fade // 48 is used for debug purposes. You can use the serial monitor to test // send this string !"#01010101 to turn on every other relay as 0 == dec(48) 1 == dec(49) if (buffer[channelIndex] > 48) { digitalWrite(channels[channelIndex], ON); } else { digitalWrite(channels[channelIndex], OFF); } } } void readSequenceData() { char buffer2[CHANNEL_COUNT]; int index = 0; while (Serial.available() < CHANNEL_COUNT) {} // We have enough data! for (int i = 0; i < CHANNEL_COUNT; i++) { int inByte = Serial.read(); buffer = inByte; Serial.write(inByte); } } void waitForControllerHeader(int header[]) { for (int i = 0; i < SIZE_OF_HEADER; i++) { // wait for serial available while (!Serial.available()) {} // Check the byte until it matches the CONTROLLER_HEADER byte int inByte = Serial.read(); if (inByte != CONTROLLER_HEADER) { i = -1; // wrong data set to "zero" } } // found the header! } // powerOnSelfTest - does a couple of checks to make sure everything turns on and off // - watch your lights, they should go on in order void powerOnSelfTest() { // This routines turns on and off each relay in order for (int channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) { digitalWrite(channels[channelIndex], ON); // turn on one channel at a time delay(2000); digitalWrite(channels[channelIndex], OFF); } // This routines turns on each relay in order leaving them all on for .5 seconds for (int channelIndex = 0; channelIndex < CHANNEL_COUNT; channelIndex++) { digitalWrite(channels[channelIndex], ON); // all on test delay(500); // wait .5 seconds } delay(2000); // slight pause to check all on turnLightsOff(); } NOTE AFTER THE SKETCH IS WRITTEN: Sketch uses 4,908 bytes (1%) of program storage space. Maximum is 262,144 bytes. Global variables use 1,104 bytes (3%) of dynamic memory, leaving 31,664 bytes for local variables. Maximum is 32,768 bytes. DSLite version 7.2.0.2096 Configuring Debugger (may take a few minutes on first launch)... Initializing Register Database... Initializing: CORTEX_M4_0 Executing Startup Scripts: CORTEX_M4_0 GEL: CORTEX_M4_0: GEL Output: Memory Map Initialization Complete Connecting... Loading Program: C:\Users\Me\AppData\Local\Temp\build426139c31db1be34a53b2333cbe6d5ea.tmp/TestSwitchMode.ino.elf Preparing ... .text: 0 of 4908 at 0x0 Erasing Flash. .data: 84 of 116 at 0x132c: 83% Finished: 83% Setting PC to entry point.: 83% Running... Failed to load dynamic library: 'ftd2xx.dll' Success
×
×
  • Create New...