Show Posts
Pages: [1] 2 3 ... 11
1  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 07:14:59 pm
Thank you Im glad I checked in again... almost didnt...
Ill check that out...  The pc end is being supplied to me so I dont need to write it just need to tap into the data and make it usable for me.
Im actually making some progress with help from another helpful guy such as yourself...  Ill post the code here if I get it running smoother... but I'm accessing all data now so its a huge step forward!!!!
2  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 03:40:56 pm
Sorry, I think I inadvertently derailed the thread..
3  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 03:39:22 pm
I get it but this industry doesn't work like that...
We learn as we go... We learn from what we need and what we need changes everyday...
We don't have time for structured classes... Just this week I'll be putting in over 90 hours...
We dream it up and make it happen... Usually by learning that's why this forum is amazing to me...
I started building with arduino a few years back and every show they want more and always deliver....
If I could have taken computer science I would have and gotten a very well rounded solid foundation on the subject, but I got in this doing animatronics.... Programming was not part of my job description but now arduino changed all of that...
When I introduced it to the studio with a programmable LED solution I got a wow.... Next week they wanted it wireless... Then servo integration, then programmable animations, etc etc...
If you ask me how to do any of that It would be a very different scenario, but this week it's about decoding packets and it's new to me...

But like I said that's how we roll.... And I always do my best and have yet to fail so every time you see me post a question I'll be the Newby but I do give back to the community on what I feel comfortable answering...

Everything I know started as a stupid Newby question... Kinda proud of that actually
4  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 03:01:26 pm
Yup, thats how we roll!
Sorry your having a bad day man, but if it makes you feel better we dont have a huge budget (budgets are relative) and never had all the time in the world either...  Its a project we all volunteered to be a part of because when it gets to comicon it puts big smiles on lots of faces.... hope to see you there my friend;)

This forum has always been about sharing projects and knowledge, learning and teaching...
Makes me a bit sad to get negative vibes when I post a legitimate question, but hopefully some day Ill be the one with the knowledge and desire to both help and motivate others with similar interests.
5  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 02:06:22 pm
Thanks Robin2!
I am neither young nor fit but Ive been under these deadlines enough not to stress smiley
here is what we are building as well as what we built last year....

We are no where near done  smiley-confuse

http://video.wired.com/series/how-to-make-a-giant-robot-mech

6  Using Arduino / Programming Questions / Re: Using packed binary data from pc serial on: July 18, 2014, 02:01:25 pm
The data is streaming from a PC on COM5
Binary data packets with identifiers other than the fact that the packet ended (dont understand what code tells us that since I cant see it but guessing its like /n????)
I say this because I see the data on a serial sniffer and IT knows that the data is in packets and shows them as groups of binary data in the format I described above.

I do know that for it to be in the

uint8_t type;
    uint8_t id;
    uint16_t pose;

format, type=1

and for this format:
    uint8_t type;
    uint8_t id;
    int16_t roll;
    int16_t pitch;
    int16_t yaw;
type=2
7  Using Arduino / Programming Questions / Using packed binary data from pc serial on: July 18, 2014, 12:50:53 pm
I am in a bit of a bind...
I have two days to interface a device to arduino and have a huge learning curve ahead of me.

I need to take incoming packed binary data, unpack it & convert it to decimal values

the incoming binary data packets are coming from a pc to an arduino on COM5 the data packets are in  these two formats:

uint8_t type;
    uint8_t id;
    uint16_t pose;

or

    uint8_t type;
    uint8_t id;
    int16_t roll;
    int16_t pitch;
    int16_t yaw;

I wanted to get the data with an identifier and comma seperated ending in /n but this is what I have to work with instead.
I have no experience working with binary and am at a loss...  looking on the forum and online didnt bring up any base sketches that I could pull knowledge from.

Any help with code, hints, or links would be HUGE!!!
8  Using Arduino / Project Guidance / Re: Where do I find documentation on readStr()? on: June 25, 2014, 01:05:08 pm
Ok Guys, sorry for the big time waster.

I just realized that you where talking about the function I missed in the code and not the line calling the function.
I am not used to seeing them above the loop() function so I guess I probably looked only below.

Thanks for taking the time to reply
9  Using Arduino / Project Guidance / Re: Where do I find documentation on readStr()? on: June 24, 2014, 05:41:19 pm
Its not a function in the code...  at least not that I could find...I posted the code above...
Im assuming its not an arduino function since its not in reference
So by process of elimination must be a c++ function
Just thought it odd that it works but is not attached to a library like Serial.readStr()
and is not mentioned in the arduino reference section....
10  Using Arduino / Project Guidance / Re: Where do I find documentation on readStr()? on: June 24, 2014, 03:23:21 pm
Ok wise guy!  smiley

I just posted the code as reference.  What I want to know is where I should look for documentation on arduino.cc for this command.
Found readString() but not readStr(#,#)
Is it the same thing???
11  Using Arduino / Project Guidance / Re: Where do I find documentation on readStr()? on: June 24, 2014, 11:41:19 am
looks like it but its specifically readStr() not readString()...
looks like it does the same thing but thats why I cant find it anywhere..

Heres the code:

Code:
/*--------------------------------------------------------------------------
  GUGGENHAT: a Bluefruit LE-enabled wearable NeoPixel marquee.

  Requires:
  - Arduino-compatible microcontroller board.  Most mainstream ATmega-based
    boards (Uno, Micro, etc.) should work; cutting-edge boards (Teensy 3,
    Arduino Due, Netduino) are untested and likely not compatible.
  - Adafruit Bluefruit LE nRF8001 breakout: www.adafruit.com/products/1697
  - 4 Meters 60 NeoPixel LED strip: www.adafruit.com/product/1461
  - 3xAA alkaline cells, 4xAA NiMH or a beefy (e.g. 1200 mAh) LiPo battery.
  - Late-model Android or iOS phone or tablet running nRF UART or
    Bluefruit LE Connect app.
  - BLE_UART, NeoPixel, NeoMatrix and GFX libraries for Arduino.

  Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
  MIT license.  All text above must be included in any redistribution.
  --------------------------------------------------------------------------*/

#include <SPI.h>
#include <Adafruit_BLE_UART.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_GFX.h>

// NEOPIXEL STUFF ----------------------------------------------------------

// 4 meters of NeoPixel strip is coiled around a top hat; the result is
// not a perfect grid.  My large-ish 61cm circumference hat accommodates
// 37 pixels around...a 240 pixel reel isn't quite enough for 7 rows all
// around, so there's 7 rows at the front, 6 at the back; a smaller hat
// will fare better.
#define NEO_PIN     6 // Arduino pin to NeoPixel data input
#define NEO_WIDTH  144 // Hat circumference in pixels
#define NEO_HEIGHT  8 // Number of pixel rows (round up if not equal)
#define NEO_OFFSET  (((NEO_WIDTH * NEO_HEIGHT) - 240) / 2)

// Pixel strip must be coiled counterclockwise, top to bottom, due to
// custom remap function (not a regular grid).
Adafruit_NeoMatrix matrix(NEO_WIDTH, NEO_HEIGHT, NEO_PIN,
  NEO_MATRIX_BOTTOM  + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  NEO_GRB         + NEO_KHZ800);

char          msg[45]       = {0};            // BLE 20 char limit + NUL
uint8_t       msgLen        = 0;              // Empty message
int           msgX          = matrix.width(); // Start off right edge
unsigned long prevFrameTime = 0L;             // For animation timing
#define FPS 30                                // Scrolling speed

// BLUEFRUIT LE STUFF-------------------------------------------------------

// CLK, MISO, MOSI connect to hardware SPI.  Other pins are configrable:
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RST  9
#define ADAFRUITBLE_RDY  2 // Must be an interrupt pin

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(
  ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
aci_evt_opcode_t  prevState  = ACI_EVT_DISCONNECTED;

// STATUS LED STUFF --------------------------------------------------------

// The Arduino's onboard LED indicates BTLE status.  Fast flash = waiting
// for connection, slow flash = connected, off = disconnected.
#define LED 13                   // Onboard LED (not NeoPixel) pin
int           LEDperiod   = 0;   // Time (milliseconds) between LED toggles
boolean       LEDstate    = LOW; // LED flashing state HIGH/LOW
unsigned long prevLEDtime = 0L;  // For LED timing

// UTILITY FUNCTIONS -------------------------------------------------------

// Because the NeoPixel strip is coiled and not a uniform grid, a special
// remapping function is used for the NeoMatrix library.  Given an X and Y
// grid position, this returns the corresponding strip pixel number.
// Any off-strip pixels are automatically clipped by the NeoPixel library.
uint16_t remapXY(uint16_t x, uint16_t y) {
  return y * NEO_WIDTH + x - NEO_OFFSET;
}

// Given hexadecimal character [0-9,a-f], return decimal value (0 if invalid)
uint8_t unhex(char c) {
  return ((c >= '0') && (c <= '9')) ?      c - '0' :
         ((c >= 'a') && (c <= 'f')) ? 10 + c - 'a' :
         ((c >= 'A') && (c <= 'F')) ? 10 + c - 'A' : 0;
}

// Read from BTLE into buffer, up to maxlen chars (remainder discarded).
// Does NOT append trailing NUL.  Returns number of bytes stored.
uint8_t readStr(char dest[], uint8_t maxlen) {
  int     c;
  uint8_t len = 0;
  while((c = BTLEserial.read()) >= 0) {
    if(len < maxlen) dest[len++] = c;
  }
  return len;
}

// MEAT, POTATOES ----------------------------------------------------------

void setup() {
  matrix.begin();
  //matrix.setRemapFunction(remapXY);
  matrix.setTextWrap(false);   // Allow scrolling off left
  matrix.setTextColor(matrix.Color(0, 0, 255)); // Red by default
  matrix.setBrightness(250);    // Batteries have limited sauce

  BTLEserial.begin();

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop() {
  unsigned long t = millis(); // Current elapsed time, milliseconds.
  // millis() comparisons are used rather than delay() so that animation
  // speed is consistent regardless of message length & other factors.

  BTLEserial.pollACI(); // Handle BTLE operations
  aci_evt_opcode_t state = BTLEserial.getState();

  if(state != prevState) { // BTLE state change?
    switch(state) {        // Change LED flashing to show state
     case ACI_EVT_DEVICE_STARTED: LEDperiod = 1000L / 10; break;
     case ACI_EVT_CONNECTED:      LEDperiod = 1000L / 2;  break;
     case ACI_EVT_DISCONNECTED:   LEDperiod = 0L;         break;
    }
    prevState   = state;
    prevLEDtime = t;
    LEDstate    = LOW; // Any state change resets LED
    digitalWrite(LED, LEDstate);
  }

  if(LEDperiod && ((t - prevLEDtime) >= LEDperiod)) { // Handle LED flash
    prevLEDtime = t;
    LEDstate    = !LEDstate;
    digitalWrite(LED, LEDstate);
  }

  // If connected, check for input from BTLE...
  if((state == ACI_EVT_CONNECTED) && BTLEserial.available()) {
    if(BTLEserial.peek() == '#') { // Color commands start with '#'
      char color[7];
      switch(readStr(color, sizeof(color))) {
       case 4:                  // #RGB    4/4/4 RGB
        matrix.setTextColor(matrix.Color(
          unhex(color[1]) * 17, // Expand to 8/8/8
          unhex(color[2]) * 17,
          unhex(color[3]) * 17));
        break;
       case 5:                  // #XXXX   5/6/5 RGB
        matrix.setTextColor(
          (unhex(color[1]) << 12) +
          (unhex(color[2]) <<  8) +
          (unhex(color[3]) <<  4) +
           unhex(color[4]));
        break;
       case 7:                  // #RRGGBB 8/8/8 RGB
        matrix.setTextColor(matrix.Color(
          (unhex(color[1]) << 4) + unhex(color[2]),
          (unhex(color[3]) << 4) + unhex(color[4]),
          (unhex(color[5]) << 4) + unhex(color[6])));
        break;
      }
    } else { // Not color, must be message string
      msgLen      = readStr(msg, sizeof(msg)-1);
      msg[msgLen] = 0;
      msgX        = matrix.width(); // Reset scrolling
    }
  }

  if((t - prevFrameTime) >= (1000L / FPS)) { // Handle scrolling
    matrix.fillScreen(0);
    matrix.setCursor(msgX, 0);
    matrix.print(msg);
    if(--msgX < (msgLen * -6)) msgX = matrix.width(); // We must repeat!
    matrix.show();
    prevFrameTime = t;
  }
}
12  Using Arduino / Project Guidance / Where do I find documentation on readStr()? on: June 24, 2014, 11:30:57 am
I saw this command in a sketch I need to modify and cant find it in reference?
13  Using Arduino / Programming Questions / Re: Why does my sketch only work when Serial command is active? on: May 06, 2014, 08:09:29 pm
Ok found error but not why it malfunctioned..
It turns out it had nothing to do with the serial lines or libraries.  Had the line
Code:
if (turbinePos>=2 || turbinePos<8) { //handle all normal spin positions
should have been:
Code:
if (turbinePos>=2 && turbinePos<8) { //handle all normal spin positions

I still dont understand how that error worked when the serial was active and failed when serial was removed...
I would love to know the answer....

Below is the routine for one of 3 animations happening simultaneously.  all other functions worked perfectly alone or in conjunction with each other with and without serial....this is the only part of my sketch that failed when serial was turned off...
All variables are comming from RC inputs and the main loop only reads those variable values and does a show() function to light the leds per the array data calculated here.

Code:
void turbineEffect(){
  if (millis()-timerTurbine > turbDelay){ // create delay
    //Loop lights around
    if (turbinePos==0 ){ //handle trail when its split between start and end of strip
      stripValues[turbinePos].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos].fadeLightBy(0);
      stripValues[turbinePos+6].setRGB(0,0,0);
      stripValues[turbinePos+6].fadeLightBy(0);
      stripValues[turbinePos+7].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+7].fadeLightBy(210-turbDim);
      stripValues[turbinePos+8].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+8].fadeLightBy(0);
      stripValues[turbinePos+14].setRGB(0,0,0);
      stripValues[turbinePos+14].fadeLightBy(0);
      stripValues[turbinePos+15].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+15].fadeLightBy(210-turbDim);
      stripValues[turbinePos+16].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+16].fadeLightBy(0);
      stripValues[turbinePos+22].setRGB(0,0,0);
      stripValues[turbinePos+22].fadeLightBy(0);
      stripValues[turbinePos+23].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+23].fadeLightBy(210-turbDim);
      
    }
    if (turbinePos==1 ){//handle trail when its split between start and end of strip
      stripValues[turbinePos-1].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos-1].fadeLightBy(210-turbDim);
      stripValues[turbinePos].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos].fadeLightBy(0);
      stripValues[turbinePos+6].setRGB(0,0,0);
      stripValues[turbinePos+6].fadeLightBy(0);
      stripValues[turbinePos+7].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+7].fadeLightBy(210-turbDim);
      stripValues[turbinePos+8].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+8].fadeLightBy(0);
      stripValues[turbinePos+14].setRGB(0,0,0);
      stripValues[turbinePos+14].fadeLightBy(0);
      stripValues[turbinePos+15].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+15].fadeLightBy(210-turbDim);
      stripValues[turbinePos+16].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+16].fadeLightBy(0);
      stripValues[turbinePos+22].setRGB(0,0,0);
      stripValues[turbinePos+22].fadeLightBy(0);
    }
    if (turbinePos>=2 && turbinePos<8){ //handle all normal spin positions
      stripValues[turbinePos-2].setRGB(0,0,0);
      stripValues[turbinePos-2].fadeLightBy(0);
      stripValues[turbinePos-1].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos-1].fadeLightBy(210-turbDim);
      stripValues[turbinePos].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos].fadeLightBy(0);
      stripValues[turbinePos+6].setRGB(0,0,0);
      stripValues[turbinePos+6].fadeLightBy(0);
      stripValues[turbinePos+7].setRGB(inputR,inputG,inputB);
    stripValues[turbinePos+7].fadeLightBy(210-turbDim);
      stripValues[turbinePos+8].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+8].fadeLightBy(0);
      stripValues[turbinePos+14].setRGB(0,0,0);
      stripValues[turbinePos+14].fadeLightBy(0);
      stripValues[turbinePos+15].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+15].fadeLightBy(210-turbDim);
      stripValues[turbinePos+16].setRGB(inputR,inputG,inputB);
      stripValues[turbinePos+16].fadeLightBy(0);
    }
    timerTurbine=millis(); //reset clock
    turbinePos++; //move to next led position
    if (turbinePos>=8) turbinePos=0; //check to see that we are not going to far
  }
}
14  Using Arduino / Programming Questions / Why does my sketch only work when Serial command is active? on: May 06, 2014, 07:10:31 pm
I have a very odd problem.
I am running some neopixels using the FastLED library and adjusting them using the PPMrcIn library
My sketch works perfectly when I debug.  There is a Serial.begin(9600); line in Setup() and a Serial.print("Hello"); line in the main program.

When I remove only the Serial.Begin(9600) line the program still works.
When I remove only the Serial.print("Hello"); line the program still works.
If I remove both, the leds dont light up at all.

I thought maybe I could add a delay(10) t take the place of the Serial lag but that didnt help.

Any one else run into this before???

There are no other serial commands in my sketch so I am really confused....

Its a really big sketch with 12 channels being read and 3  simultaneous led sequences across 150 some pixels so the code is long but I can post it if it would help...
15  Using Arduino / Programming Questions / Re: Need help with my first non linear program on: April 23, 2014, 05:52:41 pm
THANKS FOR THE HELP!!!!

Did a little reading up on C++ and Just got it working!
Here is the code.  I do have one last question...
My setup() section looks like this:
void setup() {
  strip.begin();
...
...
...
   c1.flag=1;
    c2.flag=1;
    c3.flag=2;
}

for every instance I still need to define these variables for my sketch to work.
Is there a way to put these initial values somewhere in the  class so that I only have to say to start with a value of 1 once and not have to assign a value to many individual instances????

MAIN SKETCH
Code:
#include <Adafruit_NeoPixel.h>
#include "cylon_pattern.h"

cylon_pattern c1;
cylon_pattern c2;
cylon_pattern c3;
uint32_t stripValues[40];//create array to store all led position values
#define PIN 2
#define num_LEDS 40
Adafruit_NeoPixel strip = Adafruit_NeoPixel(num_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  for (int i=0; i<strip.numPixels(); i++){//set all leds to off and load array of off values
    stripValues[i]=0;
    strip.setPixelColor(i, stripValues[i]);
  }
  strip.show(); // Initialize all pixels to 'off'
  c1.flag=1;
    c2.flag=1;
    c3.flag=2;
}

void loop() {

   cylon(strip.Color(0, 255,0),20,10,25,4, &c1);//color,firstLED,delay,LastLED,number of LEDs in chase, pointer to cylon struct
  cylon(strip.Color(0, 0, 255),10,0,40,2, &c2);
  cylon(strip.Color(255, 0, 0),5,0,40,2, &c3);
  showLEDS();//display the loaded array on LED strip
}

void showLEDS(){//display the loaded array on LED strip
  for (int i=0; i<strip.numPixels(); i++){
    strip.setPixelColor(i, stripValues[i]);
  }
  strip.show();
}


CYLON TAB
Code:
//Cylon lights (back and forth)

void cylon(uint32_t c, int wait, int firstLED, int lastLED,int numLEDS, cylon_pattern* cp) { //color, speed(millis),firstLED,LastLED,number of LEDs in chase
  if (millis()-cp->pattern_start_time > wait){//do something only if delay parameter is met
    if (cp->flag==1) {// if at start of sequence determine first led position
      cp->current_LED=firstLED;
      cp->flag=2;
    }

    if (cp->flag==2){//slide leds down strip
      if (cp->current_LED>firstLED  && cp->current_LED>0)stripValues[cp->current_LED-1]= 0;
      for (int i=cp->current_LED; i < cp->current_LED+numLEDS; i++) {
        stripValues[i]= c;    //turn every third pixel on
      }
      strip.show();
      cp->current_LED+=1;
      if (cp->current_LED+numLEDS>=lastLED || cp->current_LED>=strip.numPixels()){// if at end of strip or working space then move to next section
        cp->flag=3;
      }
    }
    if (cp->flag==3){//move LEDS backwards towards start

      for (int i=cp->current_LED; i < cp->current_LED+numLEDS; i++) {
        stripValues[i]=c;    //turn every third pixel on
      }
      if (cp->current_LED+numLEDS<lastLED && cp->current_LED+numLEDS<strip.numPixels()-1 )stripValues[cp->current_LED+numLEDS+1]= 0;

      strip.show();
      cp->current_LED-=1;
      if (cp->current_LED<=firstLED || cp->current_LED<=0){//if at start of strip or strip work area then restart requence
        cp->flag=1;
      }
    }
    cp->pattern_start_time=millis();
  }
}

CYLON_PATTERN.H TAB
Code:
#ifndef CYLON_PATTERN_H
#define CYLON_PATTERN_H

typedef struct
{
 // unsigned long wait_delay;
  unsigned long pattern_start_time;
  int flag;
  int current_LED;
} cylon_pattern;

#endif
Pages: [1] 2 3 ... 11