Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 05:02:02 pm
Robin — I have been using your "technique" as soon as you posted it.

The issue is that my baud rates seem to upset things.

I will give your exact code a go tomorrow.


James
2  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 04:30:39 pm
So I found this: http://www.gammon.com.au/forum/?id=11425

It doesn't seem so different — except that it uses a function.

Is this the key?

3  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 04:14:26 pm
Aha!

Thanks GoForSmoke

In the end I got Python to work — but again only at the slower speed — your explanation makes sense.

Here's the Python code:

Code:
import serial
ser = serial.Serial('/dev/tty.usbmodem1421', 76800)

startMarker = serial.to_bytes([254])
endMarker = serial.to_bytes([255])
bright = serial.to_bytes([32])

import time

time.sleep(2)

ser.write(startMarker)

for x in range(0, 24):
ser.write(bright)

ser.write(endMarker)

time.sleep(2)
4  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 03:43:02 pm
Turns out this should work better, but still no luck.

Code:
startMarker = serial.to_bytes([254])
endMarker = serial.to_bytes([255])
bright = serial.to_bytes([64])
5  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 03:22:25 pm
I've switched over to Python — as that is what I intend to use eventually anyway.

No luck with this:

Code:
import serial
ser = serial.Serial('/dev/tty.usbmodem1421', 115200)

startMarker = bytes(254)
endMarker = bytes(255)
bright = bytes(128)

import time

time.sleep(2)

ser.write(startMarker)

for x in range(0, 23):
ser.write(bright)

ser.write(endMarker)


6  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 01:03:14 pm
It is something to do with speed.

I altered my processing code to this and I get a much better result.

Code:
  for (int i = 0; i < leds; i++) {
    myPort.write(bright);
    delay(1);
    myPort.write(bright);
    delay(1);
    myPort.write(bright);
    delay(1);
  }

Adding in a 1ms delay between output seems to have helped.
7  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 12:12:54 pm
Thanks — done that — no difference.

Now I am left with:

Code:
#include "FastLED.h"

//setup LEDs
const int NUM_LEDS = 8;
const int DATA_PIN = 12;
CRGB leds[NUM_LEDS];
CRGB temp[NUM_LEDS];
CRGB tempBuff[NUM_LEDS];

//setup software serial buffer
const byte startMarker = 254;
const byte endMarker = 255;
const int NUM_LED_BYTES = NUM_LEDS * 3;
byte buff[NUM_LED_BYTES];
int buffPos = 0;
byte buffChar;
boolean inProgress = false;

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

  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  //Temporal dithering
  FastLED.setDither(1);

  //test LEDs to prove they're working
  testleds();

}

void loop()
{
  while (Serial.available() > 0) {
    buffChar = Serial.read();

    //Serial.print(buffChar);


    switch (buffChar)
    {
       
        case startMarker :
          memset(buff, 0, NUM_LED_BYTES);
          inProgress = true;
          buffPos = 0;
        break;

        case endMarker :
          //memset(leds, 0, sizeof(leds));   
          memcpy(leds, buff, NUM_LED_BYTES);
          inProgress = false;
        break;

        default :
          buff[buffPos] = buffChar;
          buffPos++;

    }
}

  //update LEDs
  FastLED.show();
}
8  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 11:56:55 am
So this is what I am up to now:

Code:
void loop()
{
  while (Serial.available() > 0) {
    buffChar = Serial.read();

    switch (buffChar)
    {
       
        case startMarker :
          memset(buff, 0, sizeof(buff));
          inProgress = true;
          buffPos = 0;
        break;
       
        case endMarker :
          memset(leds, 0, sizeof(leds));   
          memcpy(leds, buff, sizeof(leds));
          inProgress = false;
        break;

        default :
          buff[buffPos] = buffChar;
          buffPos++;

    }
}

  //update LEDs
  FastLED.show();
}


I am using processing with this code:

Code:
void showLED(int leds, int bright)
{
 
  myPort.write(254);
 
  println(bright);
 
  bright = formatByte(bright);
 
  for (int i = 0; i < leds; i++) {
    myPort.write(bright);
    myPort.write(bright);
    myPort.write(bright);
  }
 
  myPort.write(255);
 
      println();
 
}


Am I being naive in thinking that the code is right if it's working at lower speeds but not at higher? Jumping to conclusions and blaming the hardware?

9  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 11:28:42 am
Thanks both of you again for your replies.

Apologies for not posting up the NUM_LED stuff — I am only using 8 LED at the moment so 24 bytes in total. For the framebuffer I'm keeping it small for now so it'll fit in memory.

Robin — certainly no allegations your way about the quality of your code. I abstracted it and fitted it in with what I was doing, see here:

Code:
void loop()
{
  while (Serial.available() > 0) {
    buffChar = Serial.read();

    //Serial.print(buffChar);

    if (buffChar == endMarker) { 
      //Serial.println("End capture");
      memset(leds, 0, sizeof(leds));   
      memcpy(leds, buff, sizeof(leds));
      inProgress = false;

    }

    if ((buffChar != startMarker || buffChar != endMarker) && inProgress) {
      //Serial.println("Capture");
      buff[buffPos] = buffChar;
      buffPos++;
    }

    if (buffChar == startMarker) {
      //Serial.println("Begin capture");
      memset(buff, 0, sizeof(buff));
      inProgress = true;
      buffPos = 0;
    }

  }

  //update LEDs
  FastLED.show();
}


This works perfectly at slower speeds but at 115200 I get missing bytes.

@GoForSmoke — thanks for the ideas around being thrifty with bits. My ultimate plan with this is to get it working over a wireless serial link — which also makes me question around the quality of the link and chance of corruption!


James



James
10  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 08:31:36 am
I wonder if this can be done efficiently given the fact that I'm always sending three values at a time - R, G and B

If there were error correction it could even be "lossy" as the numbers don't need to be _that_ accurate.
11  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 07:51:51 am
Hmmmm — I am hoping to avoid something that goes two ways where it would ask the computer to send again.

An small overhead for error correction would be ok.
12  Using Arduino / Programming Questions / Re: Arrays and framebuffers on: July 12, 2014, 06:37:10 am
Hi all,


So I had a go using the same technique as Robin — and found that the issue I had was with the baud rate — mine just doesn't like 115200. For some reason bytes were going missing.

Have now set it on 76800 and don't have any issues.

So now the question is— which technique uses the least CPU and bandwidth. For my application it doesn't make much difference above 240 so I can use any of those as codes— the LED's I'm using are basically full bright from 230 upwards anyway.


James
13  Using Arduino / Displays / Re: 0.96 oled with 4 pins wont work? on: July 10, 2014, 03:35:06 pm
Aha! Yes, U8GLIB_SH1106_128X64 works perfect!

14  Using Arduino / Displays / Re: 0.96 oled with 4 pins wont work? on: July 10, 2014, 12:33:49 pm
**IGNORE THIS POST AND READ THE NEXT REPLY**

Ignore that — edited the file "u8g_dev_ssd1306_128x64.c" to this:

Code:
static const uint8_t u8g_dev_ssd1306_128x64_data_start[] PROGMEM = {
  U8G_ESC_ADR(0),           /* instruction mode */
  U8G_ESC_CS(1),             /* enable chip */
  0x010, /* set upper 4 bit of the col adr to 0 */
  0x002, /* set lower 4 bit of the col adr to 0  */
  U8G_ESC_END                /* end of sequence */
};

FYI my display is a 1.3" OLED
15  Using Arduino / Displays / Re: 0.96 oled with 4 pins wont work? on: July 10, 2014, 12:29:36 pm
Thanks to this thread I got my display working!

Hurrah!

The only issue is that the output is shifted over to the left by what looks like two pixels — and I get a white line of pixels down the right hand side of the display.



James
Pages: [1] 2 3 ... 10