danhett / virago

A lighting controller for Sonia Sabri's "Virago" show
0 stars 0 forks source link

'Base' XBEE messages #3

Open jrmedd opened 7 years ago

jrmedd commented 7 years ago

Dom needs reassurance that the 'base' XBEE will receive the correct messages.

jrmedd commented 7 years ago

Will check XBEE reference/Serial reference

jrmedd commented 7 years ago

Examples I found look like they use software serial:

/*****************************************************************
XBee_Serial_Passthrough.ino

Set up a software serial port to pass data between an XBee Shield
and the serial monitor.

Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.

*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}
jrmedd commented 7 years ago

Example code for separating wireless messages via one serial port (Arduino):

int thisDevice = 3; //identifier for messages meant for this device
int globalMessage = 0; //identifier meant for messages to all devices
ā€¦
blah blah rest of program
...
int header = Serial.parseInt();
int red = Serial.parseInt();
int green= Serial.parseInt();
int blue = Serial.parseInt();

if (Serial.read() = ā€˜\nā€™) {
    if (header == thisDevice || header == globalMesage) {
        blah(red, green, blue);
    }
}
jrmedd commented 7 years ago

Just had a phone call with @predacomdom. Seems like some assumptions around setups have gotten crossed over, unless of course @danhett's Processing sketch is yet to catch up with the actual setup.

My assumption was that 2 Arduinos would be connected to the control laptop (running the Processing sketch). One would address the length of 192 Neopixels (over a wired connection, whether that was a long USB cable or USB extended over Cat5 etc.)

The other Arduino would have an Xbee attached to it, and would relay serial messages to the wireless units. We'd need to prepend all colour messages with an integer identifying the device that would be altered (or else have 'global' or 'universal' integer that makes them all change simultaneously).

Alternatively, Dom's just said that the Xbee explorer dongle appears as a serial port, which communicates directly with the other Xbees. In this case, you'd ditch the Arduino with Xbee on top, and communicate directly with the explorer dongle (as though it were a USB cable simultaneously attached to 5 other Arduinos). Excellent solution if true!

Right now, it sounds as though the Processing sketch is setup to talk to 6 serial ports (1 wired, 5 wireless). This is not the setup that is in place!

jrmedd commented 7 years ago

FWIW, I'm going to add a branch with the wireless Arduino code based on the example I gave on a previous comment.

danhett commented 7 years ago

OK interesting - the Processing sketch serial setup is definitely not final, and was more geared to just quickly test using whatever wired units and bits I had to hand. The plan was to then wire up fully next week and adjust the code on site, as it's been hard to do remotely!

If we can just treat the dongle as a serial cable and not worry too much then great.

jrmedd commented 7 years ago

Cool. I figured. I've pushed the new wireless controller code on the branch wireless_header_messages

jrmedd commented 7 years ago

Was on the verge of modifying your P5 sketch too, @danhett, but not treading on toes ;)

predacomdom commented 7 years ago

Can't get it working with either method. Not getting any joy sending colour values via the Explorer Dongle or with the Xbee mounted on another Arduino. I've dumped the code above onto a Mega (with a pin change for compatibility) and hooked up on a breadboard, send 255 255 255 out of the serial monitor (with new line) and get nada on the Feather Arduino. I've double checked connections at both ends. The two xbees are definitely set up on the same PAN and talk happily in XCTU.

predacomdom commented 7 years ago

So, for clarity, Arduino code on Mega (host) is now

 /*****************************************************************
XBee_Serial_Passthrough.ino

Set up a software serial port to pass data between an XBee Shield
and the serial monitor.

Hardware Hookup:
  The XBee Shield makes all of the connections you'll need
  between Arduino and XBee. If you have the shield make
  sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
  the XBee's DOUT and DIN pins to Arduino pins 2 and 3.

  Note:

not all pins on the Mega and Mega 2560 support change interrupts, 
so only the following can be used for RX: 
10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), 
A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>

// XBee's DOUT (TX) is connected to pin 15 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 14 (Arduino's Software TX)
SoftwareSerial XBee(15, 14); // RX, TX

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
  }
  if (XBee.available())
  { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
  }
}
jrmedd commented 7 years ago

Ugh. This is difficult to do remotely, and I don't have any units to test on here. @predacomdom: if you're using this code: https://github.com/danhett/virago/blob/wireless_header_messages/WirelessController/WirelessController.ino you need to send a message like '0,255,127,64'

predacomdom commented 7 years ago

OK, long night. Lots of help from friendly people (one mate knocking on the studio door at 2230 and a Skype with Phoenix Perry at midnight.

OK, idea of connecting coordinator xbee via Mega is unnecessarily complex. Dumped it in favour of direct comms with the xbee via a USB explorer.

Main issue on Wirelesscontroller is that we should be using Serial1(etc) rather than Serial(etc) as the latter is reserved for USB serial (unique thing with these Arduino boards). I've updated at my end for testing. Complete GitHub noob so keeping it local atm.

I definitely have two devices talking. Confirmed in bugtesting after reflashing firmware on all devices. When xbees are connected I am getting RX lights on the router xbee when I send a packet. But the Arduino sketch still isn't passing to NeoPixels. Tried combinations of 255,0,0,0 / 255,0,0 / 255 0 0 0 / 255 0 0

Feeling positive. Getting there slowly.

jrmedd commented 7 years ago

Okay, the wireless units expect:

blockNumber, red, green, blue

e.g.

'1,128,65, 74'

jrmedd commented 7 years ago

@predacomdom, I know you're a GitHub noob, so just checking you've got the WirelessController code from the 'wireless_header_messages' branch?

predacomdom commented 7 years ago

Just clocked that... got excited... still doesn't work.

I've just resoldered everything too.

predacomdom commented 7 years ago

Yes, using that, with the header identifiers. I've updated all to Serial1 but no luck

jrmedd commented 7 years ago

Grrr. Matched the baud rates and everything? This is so hard without being able to see it!

jrmedd commented 7 years ago

Also, definitely sending a newline character at the end of your messages?

Like so:

screen shot 2017-03-04 at 11 54 57

jrmedd commented 7 years ago

If you're seeing action on the RX lights, it's weird that nothing's happening, unless the messages aren't getting parsed properly.

jrmedd commented 7 years ago

Also, dumb question, but device/global number you're typing in matches what's in the code etc? Clutching at straws!

jrmedd commented 7 years ago

Going to see if I can take Tuesday off work to come down and help on this.

stefandz commented 7 years ago

If you can get a scope on the pins, that should help. If you can't, try a simple sketch on the receiver that just listens for stuff on Serial1 and then writes it back out to Serial (the USB one). Plug the feather into a USB port and monitor its output. Do you see what you expect?

Once that's sorted, check your parsing (more use of USB Serial as a debug device - pop some prints in there where you expect to be reading stuff). Then once you know your decoding the colours correctly, you just need to link that to your Neopixel driving.

I feel you're real close!

On Sat, 4 Mar 2017 at 11:54 James Medd notifications@github.com wrote:

Grrr. Matched the baud rates and everything? This is so hard without being able to see it!

ā€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/danhett/virago/issues/3#issuecomment-284146889, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWXO5sZqA22WEw9goAM9VDvfxstAX09ks5riVDdgaJpZM4MQ8ff .

predacomdom commented 7 years ago

OMG NEWLINE!

Stef and Phoenix you are godsends! That was serial1 thing was the big piece in the puzzle. It is bloody working.

predacomdom commented 7 years ago

 #include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6
#define NUMPIXELS 32

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int thisDevice = 1; //change according to device (1-5)
int globalDevice = 0;

char colorValues[NUMPIXELS*3];
int RED;
int GREEN;
int BLUE;
int bright;

void setup() {
  bright = 128;

  // Init the NeoPixel library and turn off all the LEDs
  strip.setBrightness(bright);
  strip.begin();
  for (int i = 0; i < NUMPIXELS; i ++) {
    strip.setPixelColor(i, 0, 0, 0, 0);
  }
  strip.show();

  // Initialize serial and wait for port to open:
  Serial1.begin(9600);
  Serial1.setTimeout(3);

  while (!Serial1) {
  }
  // Tell the computer that we're ready for data
  Serial1.println("READY");

}

//We're expecting a message like '1,255,128,75' from the Processing (device,r,g,b)

void loop() {
  if (Serial1.available() > 0) {
    int header = Serial1.parseInt();
    RED  = Serial1.parseInt();
    GREEN  = Serial1.parseInt();
    BLUE = Serial1.parseInt();
    if (Serial1.read() == '\n') {
      if (header == thisDevice || header == globalDevice) {
        colourAll(RED, GREEN, BLUE);
      }
    }
  }
}

void colourAll(int r, int g, int b) {
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, r, g, b);
  }
  strip.show();
}
predacomdom commented 7 years ago

@jrmedd - I hadn't realised the packet being sent from XCTU wasn't sending a newline in the packet. As soon as I test in Ard Serial Monitor it works. Thank you soooo much!

danhett commented 7 years ago

AND THERE WAS MUCH REJOICING!

(I'm literally in the middle of teaching a gamedev workshop but did a little jump up and down anyway)

predacomdom commented 7 years ago

OMG so much rejoicing. I just did my gold dance.

So @danhett just need to update Processing sketch to output in the header format now so we can address each one individually.

predacomdom commented 7 years ago

https://goo.gl/photos/Gs9VLKGg684WEGKW7

One down, four more to go

stefandz commented 7 years ago

Love the video, Dom - powerful finish. Glad you're up and running! Well done everyone šŸ‘

danhett commented 7 years ago

Outstanding video. Boom indeed. It liiiiiives!

:D