Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: First attempt at a sketch with serial data input via XBee

  1. #11
    Join Date
    Dec 2013
    Location
    Elkridge, MD
    Posts
    786
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    Quote Originally Posted by MartinMueller2003 View Post
    In your patching, you skipped channel 1. That means channel 2 is sent to the Arduino as channel 1. Why did you skip a channel?
    When I patch everything 1-8 and turned on element 2 "Costume1 CH2-Glasses", output 1 or PIN 2 on the board turned on. Everything was off by 1 output. When I turned on preview for "Costume1 CH2-Glasses", the first output (Channel A Pin 2) turns on. When I turned on "Costume1-CH7-Right Leg" Channel 8 or PIN 9 turned on.
    Here was my original setup
    outputsetup.JPG
    so as a test, i set the controller up for 9 outputs and patched 1 to 2, 2 to 3 and so on. and the correct output turned on.
    The outputs or channels on the board are PINS 2-9 not 1-8.

  2. #12
    Join Date
    Dec 2013
    Location
    Elkridge, MD
    Posts
    786
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    So i figured you'd think I'm crazy so here is a video. The current patching is elements 1-8 are patched to outputs 2-9. the code is what I posted above.

    You can see in the video that my EL Wire is connected to the first and last outputs and they turn on when I preview element 1 or 8

    https://www.dropbox.com/s/i2hg7vuz8q...43.24.mov?dl=0

  3. #13
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,880
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    This indicates that you have configured the player to send an extra byte of information to the Arduino that the code was not expecting. I suspect it is either a NewLine or a NULL. I would NOT fix that issue by changing the patching. It makes the controllers hard to use (Unexpected rules to be followed etc). Skipping the first patch point will send an extra byte but it will result in issues with the byteID to port mapping.

    There are a few ways to fix this. In order of preference:


    • You can figure out what the extra byte is and add it to the search string definition (best solution).
    • You could add a dummy port to the start of the list of ports that will consume the extra data (not great but it will work).
    • You can add a state to the state machine to discard the first byte of data (most complex solution).


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  4. #14
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,880
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    If you want to check what is being sent, add a print statement at the top of the loop to output the hex value of every byte the Arduino receives. This will let you know what the value of the extra byte is.


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  5. #15
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,880
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    After a bit of debugging, it was found that the sync length was grabbing one too many bytes. i have corrected my original four relay post. just locate the line with sizeof in the main loop an add a -1 after the sizeof statement to reduce the number of bytes consumed by the header processing


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  6. #16
    Join Date
    Dec 2013
    Location
    Elkridge, MD
    Posts
    786
    Post Thanks / Like

    Default Re: First attempt at a sketch with serial data input via XBee

    in case anyone wants the final working code. Here it is. Here is the board its used with https://www.sparkfun.com/products/12781

    Code:
    //set Pin for Sequencer channels
    #define CHAN_1_PIN_ID 2
    #define CHAN_2_PIN_ID 3
    #define CHAN_3_PIN_ID 4
    #define CHAN_4_PIN_ID 5
    #define CHAN_5_PIN_ID 6
    #define CHAN_6_PIN_ID 7
    #define CHAN_7_PIN_ID 8
    #define CHAN_8_PIN_ID 9
    
    
    //set output status
    #define CHAN_ON HIGH
    #define CHAN_OFF LOW
    
    
    //intensity value to turn on channels
    #define CHANNEL_TRIGGER_LEVEL 128
    
    // table translate channel index to pin id
    byte XlatIndexToPin[] = 
    {
      CHAN_1_PIN_ID,
      CHAN_2_PIN_ID,
      CHAN_3_PIN_ID,
      CHAN_4_PIN_ID,
      CHAN_5_PIN_ID,
      CHAN_6_PIN_ID,
      CHAN_7_PIN_ID,
      CHAN_8_PIN_ID
    };
    
    byte CurrentChannelIndex = 0;
    
    // string to search for at the start of a frame so we can sync to the frame
    // you must add this string to the show player and have it sent at the start of every data frame.
    byte FrameHeader[] = {"FindMe"};
    byte FrameHeaderIndex = 0;
    
    void setup()
    {
      Serial.begin(9600);
    
      // The EL channels are on pins 2 through 9 on the ATMega328
      // set up the output ports
      for(byte CurrentPort : XlatIndexToPin)
      {
      pinMode(CurrentPort, OUTPUT);
      digitalWrite(CurrentPort, CHAN_OFF);
    
    
      } // end set up the output ports
    
    
      // set up for a new frame
      FrameHeaderIndex = 0;
      CurrentChannelIndex = 0;
    
    
    } // setup
    
    void loop()
    {
      do // once
      {
        // is there data to process?
        if(0 == Serial.available())
        {
          // no data. Go away
          break;
        } // end no data
    
        // have we completed the header sync yet
        if( FrameHeaderIndex < sizeof(FrameHeader)-1)
        {
          // still searching for the header
    
    
          // is this an expected byte?
          if( Serial.read() != FrameHeader[FrameHeaderIndex++])
          {
            // not the expected value. Start searching at the beginning again
            FrameHeaderIndex = 0;
          }
    
    
          // go away and process the next byte in the next loop iterration.
          break;
        } // end look for header
    
    
        // we get to here if this byte is ment for the relay
        digitalWrite(XlatIndexToPin[CurrentChannelIndex], (Serial.read() < CHANNEL_TRIGGER_LEVEL) ? CHAN_OFF : CHAN_ON);
    
    
        // move to the next relay
        CurrentChannelIndex++;
    
    
        // have we sent all of the relay data?
        if( CurrentChannelIndex == sizeof(XlatIndexToPin))
        {
          // start searching for the next frame
          FrameHeaderIndex = 0;
          CurrentChannelIndex = 0;
        } // end move to next frame
    
    
        
      } while(false);
    
    
    } // loop
    Last edited by JCook; 08-30-2018 at 08:16 PM.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •