Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Programming Questions / Re: 1024hz to milliseconds on: September 01, 2014, 03:09:42 pm
Why didn't used DS1307. You get accurate.problem need to use external crystal oscillator. I think it should work with library. Instead of conversion.

https://github.com/JChristensen/DS3232RTC library avialble here, Let me know if any problem in output. share your code and snapshot of the output window

Hi Jack,


I have your library working — many thanks — saved me some time.

I have set my squarewave to 1024Hz — but am unsure how to test it's actually working. I have it attached to a pin and attachInterrupt running a counter function on RISING. But no luck.
2  Using Arduino / Programming Questions / Re: 1024hz to milliseconds on: September 01, 2014, 11:23:32 am
In the same way I can get seconds() I'd like to be able to get milliseconds()

Accurate as possible within reason.

I'm using them to drive a strip of LEDs — at the moment I'm using only 60 and slight variances are noticeable. It's surprising how the eye can pick up on tiny millisecond differences. So at the moment I only need 1/60 accuracy.

I'd like a solution that is scalable to a large number of LEDs
3  Using Arduino / Programming Questions / Re: 1024hz to milliseconds on: September 01, 2014, 08:48:59 am
I read it as "I want to be able to timestamp to (roughly) millisecond accuracy"

Yup, exactly.

I'm trying to work out if using a higher hz would give me a more accurate millisecond by using the same technique.

I guess it's a case of how accurate do I need...

4  Using Arduino / Programming Questions / Re: 1024hz to milliseconds on: September 01, 2014, 07:08:35 am
So something like this:

Code:

ms += 1
fracms += 1
if (fracms == 42) {
fracms = 0
ms -= 1 }
if (ms == 1000) {
ms = 0 }


Every 42 beats it corrects itself.

Seems fair enough.
5  Using Arduino / Programming Questions / 1024hz to milliseconds on: September 01, 2014, 04:42:51 am
I need accurate time for my project — specifically milliseconds.

I plan to use a DS3231 RTC and it's 1024hz output.

I can keep count of the output but of course I am stuck with a "millisecond" of 1024 every second.

What's the most elegant way of converting a range of 0 to 1024 to 0 to 1000?

My plan is to keep a count (that rolls from 1023 to 0) and then whenever I request a millisecond do the maths to convert it from 0-999

I can either do the obvious "hzCount * (hz/1000)" or I could keep a look up table in memory and just do "msLUT[hzCount]"

The truth is that I'll probably be calling a getMillis() every loop.

Anything I'm missing? I'm really keen to learn about how to do these things as efficiently as possible.


James
6  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
7  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?

8  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)
9  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])
10  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)


11  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.
12  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();
}
13  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?

14  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
15  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.
Pages: [1] 2 3 ... 10