Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / Re: 2 dj hero decks and a crossfader - Buffer Overflow? i2c or serial? on: August 02, 2014, 03:53:30 pm
It occurs to me that if there were ever less than 23 bytes in the buffer eg 22 then the buffer is not read but another 23 bytes are requested.
Then there would  more than 23 bytes and the buffer would still not ne cleared.
In fact it would never be cleared and would hang.
Something to try tomorrow, feel I might be onto something.
Perhaps fast spinning results in a lostbyte or two.
There is no contingency for lost data or for there being any other number of bytes available other than 23.
Very bad coding. Hopefully fixing it will be the answer
2  Using Arduino / Networking, Protocols, and Devices / Re: 2 dj hero decks and a crossfader - Buffer Overflow? i2c or serial? on: August 02, 2014, 02:54:20 pm
I have tried it without the crossfader and it is the same
The wire library requests a certain number of bytes so hard to see how it could be sending too much data.
Looking at my code though I am wondering if I am leaving a byte in the buffer every time. I discard the last 2 bytes but maybe I should be discarding the last three.
I have to retain the serial.write or I won't know if its crashed or not!
So I'm either overloading the serial or wire buffer or something else!

3  Using Arduino / Networking, Protocols, and Devices / 2 dj hero decks and a crossfader - Buffer Overflow? i2c or serial? on: August 02, 2014, 01:48:54 pm
I've got issues but not sure even which section of the forum to put them in.

My sketch works but after a while it hangs, stops sending data and I have to close and open the serial port to get it to send again.

I am reading the data in Max/Msp but it hangs the serial monitor in Arduino so I am assuming/guessing the problem is with the Arduino.

I have 2 dj hero decks connected via i2c and a crossfader which sends serial data to pin 0.

It seems to hang when the decks are spun really fast but I could be imagining it.

Does closing and reopening the port restart the sketch (ie the same as hitting reset on the Arduino? I didn't think it did).

I'm not sure whether my problem is i2c or Serial port related.

Here is my sketch, its pretty simple, read the data from both decks and the crossfader, write the data and a few id bytes to the serial port.

If anyone can shed any light on this, or even help me track down the problem, you be my friend long time! Thanks

Code:
#include <Wire.h>

byte val = 0;
byte lturn=0;
byte rturn=0;
byte buf=0;
int cfade=0;
 int add=0;
 int avail=0;

void setup()
{
  Wire.begin(); // join i2c bus
  Serial.begin(38400);
}

void loop()
{
  Wire.beginTransmission(14); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet
  Wire.write(val);             // sends value byte  
  Wire.endTransmission();     // stop transmitting
  Wire.requestFrom(14, 23);

 if (Wire.available()== 23)    // slave may send less than requested
  {
     for (int i = 0; i < 20; i++) {
       Wire.read();
    
  }
   rturn=Wire.read();
    
     Wire.read();         // read the last 2 bytes
     Wire.read();        
  }
  
   Wire.beginTransmission(13); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet
  Wire.write(val);             // sends value byte  
  Wire.endTransmission();     // stop transmitting
  Wire.requestFrom(13, 23);

 if (Wire.available()== 23)    // slave may send less than requested
  {
     for (int i = 0; i < 20; i++) {
       Wire.read();
    
  }
  lturn=Wire.read();
     Wire.read();         // read the last 2 bytes
     Wire.read();        
  }
  
    
      
          
  
 
  Serial.write(rturn);
  Serial.write(200);
  Serial.write(lturn);
  Serial.write(70);
  Serial.write(cfade);
  Serial.write(143);
 
  delay(25);
}


void serialEvent(){
  
 
avail=Serial.available();
   for (int i = 0; i < avail; i++) {
    buf = Serial.read();
   }
    if (buf==255) {
    add=128; }
    else {
      
   cfade=buf % 128;
   cfade=cfade + add;
   //Serial.println(cfade);
   add=0;
    }
  
    
  }
    
  
 
4  Using Arduino / Programming Questions / Re: Corrupt IR Codes - coding error? on: December 16, 2013, 09:22:21 am
Oh yes sorry, its a TSOP4838 - data sheet here: http://datasheet.octopart.com/TSOP4838-Vishay-datasheet-5390783.pdf

I think my problem is to do with interrupts. The neopixel library temporarily disables interrupts.
As I reduce the frequency of the light updates, the ir becomes more reliable.

I could probably live with this but I probably need to think about mrburnette's approach.
5  Using Arduino / Programming Questions / Re: Corrupt IR Codes - coding error? on: December 16, 2013, 07:16:04 am
Thanks for the tips.

mrburnette, using something like the tiny85 may well be the best approach - I'd like to see what the problem is first though if possible.
AnalysIR, thanks for your suggestions. I've tried all of them except for the decoupling capacitors which I don't have here.
No joy though, even when I am sending 'all off' data to the lights, the ir signal is corrupted.

6  Using Arduino / Programming Questions / Re: Corrupt IR Codes - coding error? on: December 15, 2013, 01:56:00 pm
Hmm. Or maybe it's something to do with the neopixel library turning off interrupts.

Why would that corrupt the values though?

I'm confused.
7  Using Arduino / Programming Questions / Corrupt IR Codes - coding error? on: December 15, 2013, 11:53:53 am
Hello,

I'm trying to combine Ken Schirrffs IR library with the Adafruit Neopixel library but I'm having issues.
The Ir code works fine on its own but when I integrate it with the led code (also working fine) the ir codes seem to get corrupted.
I'm not sure if this is something to do with the received code getting overwritten where it is stored in memory?

I've tried commenting out different parts of code and it works fine until I actually send data to the light string using the ColorBlip function.

Anyone shed any light on this?


Code:
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
int numpixels=51;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numpixels, 6, NEO_GRB + NEO_KHZ800);
int RECV_PIN = 2;
int code;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  Serial.println("working");
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  
  colorBlip(strip.Color(255, 0, 0), 25);
  
}

void testfunc() {
  for (int i=0;i<1000;i++) {
  Serial.println(checkir());
  }
}

void colorBlip(uint32_t c, uint8_t wait) {
  for (int j=0; j<10;j++) {
    for(uint16_t i=0; i<strip.numPixels(); i++) {
      checkir();
//      switch(checkir()) {
//      case -1:
//       return;
//      case 1:
//        c=strip.Color(255,0,255);
//        break;
//      case 2:
//        c=strip.Color(0,255,0);
//        break;
//      case 3:
//        c=strip.Color(255,255,0);
//        break;
//      case 4:
//        c=strip.Color(0,0,255);
//        break;
//      }
      strip.setPixelColor(i, c);
      strip.setPixelColor(numpixels-i, c);
      
      strip.show();
      delay(wait);
      strip.setPixelColor(i, 0);
      strip.setPixelColor(numpixels-i, 0);
    }
  }
}
  

uint8_t checkir() {
  
   if (irrecv.decode(&results)) {  
    long int decCode = results.value;
    Serial.println(decCode);
    switch (decCode) {
      case 49796:
        //Serial.println("One");
        code=1;
        break;
 
      case 49836:
        Serial.println("Time");
        code= -1;
        break;
      case 49872:
        //Serial.println("Off");
        code=2;
        break;
      case 49859:
        //Serial.println("Review");
        code=3;  
        break;
      case 49688:
        //Serial.println("Down");
        code=4;  
        break;
    
    }

    irrecv.resume(); // Receive the next value
    
  }
  return code;
}
8  Using Arduino / Programming Questions / Re: Am I wasting time with an Interrupt in this case? on: November 23, 2013, 10:08:48 am
Ok - thanks all for the advice.
9  Using Arduino / Programming Questions / Am I wasting time with an Interrupt in this case? on: November 22, 2013, 04:06:31 pm
I'm writing a little sketch where a bunch of led's are turned on or off depending on whether a sensor is touched.

The led's run a series of patterns, using loops and delays, so I thought ok I'll put the sensor on an interrupt so the Arduino gets the message no matter whats going on and can act accordingly.

I set the interrupt to change mode and change a state variable to true or false depending on whether I want the lights on or off.

Thing is then I need to put a check in each of my light patterns so that they stop if the state is off.

It occurred to me that I am effectively polling the state variable instead of polling the input pin.

Is there any advantage to this or should I just forget the interrupt?

Hopefully this should explain what I mean:
Code:
void setup() {
    attachInterrupt(0, on, CHANGE);
}

void loop(){

    if (state==1) {
        rainbowCycle(1);
    }

}
void rainbow() {
   
  for (int j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
    for (int i=0; i < strip.numPixels()/2+1; i++) {
      strip.setPixelColor(i, state*Wheel( (i + j) % 255));
      strip.setPixelColor(50-i, state*Wheel( (i + j) % 255));
     if (state==0) {return;}
    strip.show();   // write all the pixels out
    }
  }
}
void change()
//set state touch or not. If not then clear matrix
{
  state=digitalRead(2);
  clrpixels();
}
10  Using Arduino / LEDs and Multiplexing / Re: Streaming Pixel Data to Arduino on: April 04, 2013, 06:43:27 pm
@tom Yes I noticed that but then I switched to the Teensy which ignores the serial rate and communicates at full USB speed.

Not sure how fast this is. 12Mb/second? Fast enough anyway.
11  Using Arduino / LEDs and Multiplexing / Re: Streaming Pixel Data to Arduino on: April 04, 2013, 06:39:59 pm
Well for me the data is coming from this processing sketch which is capturing the screen:
https://github.com/adafruit/Adalight/tree/master/Processing/Adalight
I changed the pixel info to match my set up and display the whole screen.

I'm trying to write a max patch that will do similar but for some reason it isn't working for me at the moment.
I can't seem to send 1536 bytes reliably from MaxMsp. That is my current problem!
Maybe I'll just stick with processing.

12  Using Arduino / LEDs and Multiplexing / Re: Streaming Pixel Data to Arduino on: April 04, 2013, 09:02:32 am
Ok I have connected my matrix to a Teensy 2.0 running the Adavision LedStream.pde sketch from here]https://github.com/adafruit/Adalight/blob/master/Arduino/LEDstream/LEDstream.pde

It works and I get around 22 fps - though that's probably got more to do with the processing screen capture patch (also part of adalight) feeding it than anything else.

Its a great start anyway. I'll keep the thread updated with any progress.
13  Using Arduino / LEDs and Multiplexing / Re: Streaming Pixel Data to Arduino on: March 31, 2013, 04:54:59 am
Yes I do also want to stream data from the Arduino to the lights but this is not the part that is giving me problems (not yet anyway!).

I actually want to stream data TO the arduino from a computer eg pipe low res video to the arduino and then on to the led array.

What I am finding difficult is a way of reliably sending this much data at the required rate and reading it quick enough without it getting scrambled, lost or stuttering.

Hope that is a bit clearer.
14  Using Arduino / LEDs and Multiplexing / Streaming Pixel Data to Arduino on: March 30, 2013, 04:51:36 pm
I've built a 512 pixel led array, using WS2801 modules and I'm wondering the best way of streaming data to it.

Each pixel receives 24 bits to drive its RGB led's so I think the whole matrix needs 1536 bytes a frame.

If I assume a frame rate of 25 fps thats 38400 bytes per second, so I'd need a serial baud rate of at least 307200, more if there are some extras involved with the serial communication.

This is probably too much for my Uno but I have a Teensy 2.0 here which I believe allows much faster communication.

Is it realistic to drive this size of array? There are solutions out there such as PixelController and Glediator but I haven't got them working with my set up yet.

Has anyone got any experience/tips/hints they'd be willing to pass on?

Thanks,



15  Using Arduino / Networking, Protocols, and Devices / Re: TouchOSC via Ardosc/Bonjour on: January 04, 2013, 06:31:41 am
Hey thanks for posting that code. I'll look into it.

I actually started using the z_osc library as opposed to Ardosc as I couldn't work out how to parse the incoming osc addresses using Ardosc (which I needed to do to use touch osc's multitoggle's).

I am sure this is due to inability on my part as opposed to any problems with the library. In fact I'm not even sure if there is any difference between the libraries!

I've got a basic wifi set up working now. Thanks alot for your help.

I'm wondering at what rate I can pass data to the Arduino via wifi. ie could I stream pixel data to my 20x10 array at >15fps. I never intended to do this before but now I'm wondering if its possible. Obviously it depends in part on the network. I guess OSC isn't necessarily the best way of doing this. In fact it might warrant another thread.....
Pages: [1] 2