ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#25  

The ring I think would be to pin 6 on the arduino for signal and provide power to the ring. I read something about the power should be from the same source as the arduino. This could come off of the arduino if you would like.

#26  

Dave, has the code you posted been tested? I was sending the command thru the Arduino serial monitor, should work there. I will try and send it thru the EZB.

#27  

Not at all. I dont even have an arduino yet. It should be here soon. The neopixel may be a week out or so. This was more of a conversation to get ideas in a topic that already existed. Read post #12.

#28  

Robert, what do you think about this. The V4 could set an arduino pin to high which would then be caught in the loop and kick the arduino code to a function that is looking for a serial connection to get the new values. The trigger port would be set to low again by the V4 and the arduino would see this and start the loop again using those color settings.

#29  

OK. Here's where I am at running a Neo Pixel Ring off of the EZBv4. I have to say right up front that what I am going to post is the work of our friend Luis Vazquez who has guided me thru get the ring up and running.

Connection between the EZB and the Arduino

Digital Port 18 (TX) to RX on the Arduino Digital Port 19 (RX) to TX on theArduino These are used as UART2 Connect a ground wire between the EZB and the Arduino:

Note; You can't upload a script to the Arduino with EZB powered up.

Arduino script:


 #include <Adafruit_NeoPixel.h>


#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  Serial.begin(9600);

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {


  if (Serial.available())
  {


    int ib = 0;
    ib = Serial.read();


    // Stop All display
    if (ib == 33) {
      strip.show(); // Initialize all pixels to 'off'
    }



    // ColorWipes
    // Blue = "B" or 66
    if (ib == 66) {
      colorWipe(strip.Color(0, 0, 255), 5); // Blue
      
    }
    //Blue White = "P" or 80
    if (ib == 80){
      colorWipe(strip.Color(0, 0, 255), 20);
      colorWipe(strip.Color(0, 0, 0), 30);
    }
    // Red = "R" or 82
    if (ib == 82) {
      colorWipe(strip.Color(255, 0, 0), 10); // Red

    }
    // Green = "G" or 71
    if (ib == 71) {
      colorWipe(strip.Color(0, 255, 0), 50); // Green
    }
    if (ib == 87){
      colorWipe(strip.Color(0, 0, 0), 10);
    }

    // ChaseSetting
    // White = "w" or 119
    if (ib == 119) {
        theaterChase(strip.Color(127, 127, 127), 50); // White
    }
    // Red = "r" or 114
    if (ib == 114) {
      theaterChase(strip.Color(127,   0,   0), 50); // Red

    }
    
    if (ib == 98)
    {
     theaterChase(strip.Color(  0,   0, 127), 50); // Blue
    }
    
    if (ib == 88)
    {
    rainbow(20);
    }
  if (ib == 89)
  {
  rainbowCycle(20);
  }
  
  if (ib == 90)
  {
  theaterChaseRainbow(50);
  } 
    
    
  }



  


}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j = 0; j < 256; j++) {   // cycle all 256 colors in the wheel
    for (int q = 0; q < 3; q++) {
      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Makes sure you have the library for it.

You should be able to send it commands thru the Arduino Serial Monitor by entering the (ASCII Character). For example in the code above enter "B" or 66 and the Blue colorwipe should run.

To send the commands via the EZB.

Create an initialization script and have it run when you connect to the EZB


UARTInit( 0,2,9600 )

Create a script to send the commands to the Arduino, for example, this will run the Blue colorswipe, once.


UARTWrite(0,2,"B")

To run it multiple times you can put it in a loop.

I have found the script hard to control, for example, running in a loop if you push stop it will still run for awhile.

What I am trying to achieve is a pulsing effect that can be changed to different colors, when needed. Kind of like a mood indicator. If anyone can help out there help with a script for that, it would be great. Once again thanks Luis for all your help.

#30  

The problem is that the loops that change pixel colors have delays in them and the arduino is busy in those loops and not checking the serial port for new commands. I have seen a few notes on the subject on the Internet. It is what I meant when I said I was not sure how responsive the arduino would be to serial commands. There is a way to write it that will work. There are some articles on adafruit about multitasking an arduino which help explain the way to do it. When I get time I will see if I can whip up something close to what you need as an example.

Luis is a probably better at this stuff than I am, but we all have different things we have worked with. I have been playing with neopixels for some projects lately. I made a guggenhat a while back that mixes neopixels with serial input that has the fixes in it you need.

#31  

Couldn't you check for the pin state in the inner loops which would make it check every 50 ms? If the pin is high, jump out. Basically at that point you could set another pin high but in the opposite direction. The v4 could be set to watch for that pin to go high and start the serial write. When it is done, the v4 could set the first pin back to low. You get the idea. The unique thing here is that there are many different ports to handle flags passed back and forth between the two devices.

if you want to work on it, thate great. I will be working on it as soon as I can. I like learning new stuff.

#32  

If you want to look into using digital signals to interrupt the loops the arduino does actually support interrupts. The same adafruit multitasking an arduino tutorials actually talk about using signals pins to interrupt loops. They are a good read.

https://learn.adafruit.com/multi-tasking-the-arduino-part-1

https://learn.adafruit.com/multi-tasking-the-arduino-part-2

https://learn.adafruit.com/multi-tasking-the-arduino-part-3

I think part 3 has a lot of the fix you need but it has been a bit since I read thru them. In part 3 they get rid of the delays in the loops. The code in part 3 uses push buttons to change operations, but a serial input could be used instead. If you really want to use up digital pins on the ez-b you could use the button code as is.