Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LochNessMonster
Feb 3, 2005

I need about three fitty


rawrr posted:

Where are you located? The power bricks are easier to use since you don't need to buy separate cables and everything is in a neater package. You should be able to find 5V power bricks locally too.

I'd also see if you can buy the neopixels locally - search for something like WS2812 or SK6812 which is the led chips that the neopixel uses. Aliexpress will have them for much cheaper than adafruit.

I found the bricks locally for about the same price as adafruit has them so that's good. How do I hook it up to the strips though? They have a round plug and from what I've seen I need to solder wires to the led strip or use some kind of connector.

I've seen several local store sell Adafruit products for similar prices (but without the import tax) but I'll have a look if I can find non branded strips too.

Adbot
ADBOT LOVES YOU

rawrr
Jul 28, 2007
You can snip the round plug off and solder the wires to the strip. Check polarity with a multimeter

Rexxed
May 1, 2010

Dis is amazing!
I gotta try dis!

LochNessMonster posted:

I found the bricks locally for about the same price as adafruit has them so that's good. How do I hook it up to the strips though? They have a round plug and from what I've seen I need to solder wires to the led strip or use some kind of connector.

I've seen several local store sell Adafruit products for similar prices (but without the import tax) but I'll have a look if I can find non branded strips too.

If you solder some wires to your LED strip you can use a barrel jack to terminals thing like this:
https://smile.amazon.com/HitLights-Light-Strip-Jack-Connection/dp/B00ZGDF7AY/

Sockser
Jun 28, 2007

This world only remembers the results!




I'm looking to run somewhere between 100-150 neopixels off an arduino.

This is going to be controlled from a game I'm coding up in python, and I basically want the LEDs to just chill in a standard sine wave pattern, and just switch colors depending on some events in the game.

I assume I just need to send some serial data to my arduino and then parse it from that side, yeah? Could send it as a series of .... 12 bytes, I guess, to preserve some latency, or I could define the colors as an enumer and just send over a single byte. Is there a simpler way to do it?

Also, shouldn't matter which board I use, right? I've got a couple teensy's and an Uno and a Mega sitting around, probably just gonna use the teensy and solder it to a perf board

Sockser fucked around with this message at 01:41 on Oct 22, 2017

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Sockser posted:

I'm looking to run somewhere between 100-150 neopixels off an arduino.

This is going to be controlled from a game I'm coding up in python, and I basically want the LEDs to just chill in a standard sine wave pattern, and just switch colors depending on some events in the game.

I assume I just need to send some serial data to my arduino and then parse it from that side, yeah? Could send it as a series of .... 12 bytes, I guess, to preserve some latency, or I could define the colors as an enumer and just send over a single byte. Is there a simpler way to do it?

Also, shouldn't matter which board I use, right? I've got a couple teensy's and an Uno and a Mega sitting around, probably just gonna use the teensy and solder it to a perf board

I've run 300 neopixels with a single uno; any board will work. You need to use the fastleds library for that; you start to run out of timing to do anything else with that many pixels. Also, the strips get REALLY HOT if you just have one power connection at the end. Split the strings.

If all you're doing is changing the color with serial data, then 3 bytes is plenty to send a color. But that's probably not where your bottleneck is, so sending "0xFFEE00" over serial and parsing it is likely easier to understand and code, and not where your code is going to be spending most of its time.

Sockser
Jun 28, 2007

This world only remembers the results!




Yeah I’ve got a strip of 144 running the code I want (mostly ripped from adafruit) and it’s been running 24/7 on my desk for a long time without any significant problems, just I’m switching the colors with a button press instead of from serial, wasn’t sure where it’d get weird

And my final product is going to be something like
4 rings of 12 in series = 48
2 dense strips of about a foot each run in series = ~ 90
2 sparse strips of 3 ft each = 112

So a total of 250, I guess?

And then I’m gonna have a dedicated power supply on them

I could split it out into two separate arduino if it becomes too heavy for one to handle

Sockser fucked around with this message at 19:52 on Oct 22, 2017

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
What are the options if I want my thing (something with an atmega probably) to know what time and date it is, with the minimum amount of user provided interaction ?

A wifi module can pull the time from the internet, but credentials will be hardcoded, and it relies on a working connection.
There are circuits that receive the Frankfurt atomic clock signal (I'm in europe) but those seem like they require some processing work in case the signal isn't strong.
I haven't looked at GPS modules but can those give me what I need ?

I kinda want to try making a tide clock. Those exist but mine would store local forecasts instead of relying only on the moon. This would be a fixed device.

Ideally it would sync to local time somehow, set a clock (there's an atmel doc on the subject), and display the time to next full tide and tidal coefficient with a stepper motor moving hands or something that isn't a screen.

Sagebrush
Feb 26, 2012

A GPS module will give you an accurate UTC time code. You need to handle the time zone and daylight savings. It only works reliably in places with a view to the sky and takes a few minutes to start up and get synchronized.

A Wifi module or other internet connection can get an NTP time code. You need a wifi network nearby, obviously.

The cheapest way is to get a battery-powered RTC module, which will run for like two years on a coin cell. You just program it once and let it go.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

unpacked robinhood posted:

What are the options if I want my thing (something with an atmega probably) to know what time and date it is, with the minimum amount of user provided interaction ?

A wifi module can pull the time from the internet, but credentials will be hardcoded, and it relies on a working connection.
There are circuits that receive the Frankfurt atomic clock signal (I'm in europe) but those seem like they require some processing work in case the signal isn't strong.
I haven't looked at GPS modules but can those give me what I need ?

I kinda want to try making a tide clock. Those exist but mine would store local forecasts instead of relying only on the moon. This would be a fixed device.

Ideally it would sync to local time somehow, set a clock (there's an atmel doc on the subject), and display the time to next full tide and tidal coefficient with a stepper motor moving hands or something that isn't a screen.

pulsar clock

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass
The easiest and most reliable option is an RTC. With a little coin cell they can run for years and years keeping good time. Just set their time once and you're done. No messing around with parsing GPS data, waiting for signals, etc. Sure it won't work without that initial time setting, but in almost all cases it's far easier to set the time once ahead of time and just forget about it forever vs. futzing around constantly with locking on to a time signal.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
I have an input box on my web interface that gives me this in the serial monitor.
GET /?LEDWHITE=100&submit=Send+White+LED+Level HTTP/1.1

I want to parse the number out of the string. I tried:

code:
  int pos1 = readString.indexOf('=');
  int pos2 = readString.indexOf('&');
  newString = readString.substring(pos1 + 1, pos2);
I get nothing? When I print the variable I literally get no value.
This code was lifted from an example I found online so I have no idea what I messed up.

thegasman2000 fucked around with this message at 12:30 on Oct 26, 2017

unpacked robinhood
Feb 18, 2013

by Fluffdaddy


Thanks, I ordered one.


That's cool

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
OK So I think I am close...

I have with the help of somebody on the arduino forums got this far...

code:
#include <ESP8266WiFi.h>
#include <time.h>

// Wifi Settings
const char* ssid = "PrettyFlyForAWifi";
const char* password = "reidbuck";
WiFiServer server(80);

// Time Settings
int timezone = 3;
int dst = 0;

// LED Settings
int blueLedPin = 5;
int blueLedOn = 4;
int blueLevel = 1000;

int whiteLedPin = 0;
int whiteLedOn = 2;
int whiteLevel = 100;

bool recording = false;
int brightnessVal;
char startMarker = '=';
char endMarker = '&';



void setup() {
  pinMode(blueLedPin, OUTPUT);
  pinMode(blueLedOn, OUTPUT);
  pinMode(whiteLedPin, OUTPUT);
  pinMode(whiteLedOn, OUTPUT);
  Serial.begin(115200);
  delay(10);


  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

  // Time Config
  configTime(3 * 1200, 0, "pool.ntp.org");
  Serial.println("\nWaiting for time");
  while (!time(nullptr)) {
    Serial.print(".");
    delay(1000);
  }

  // Turn off LEDS ON BOOT

  digitalWrite(blueLedOn, LOW);
  digitalWrite(whiteLedOn, LOW);
}

void loop() {

  // Get time
  time_t now = time(nullptr);
  Serial.println(ctime(&now));
  delay(1000);

  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);

while (client.available() > 0)
  {
    char c = client.read();
    if (c == startMarker)
    {
      recording = true;
      whiteLevel = 0;
    }
    else if (c == endMarker)
    {
      recording = false;
    }
    else
    {
      if (recording) {
        if (isdigit(c)) {
          whiteLevel *= 10;
          whiteLevel += c - '0';
          analogWrite(whiteLedPin, whiteLevel);
        }
        else
          recording = false;
      }
    }
  }
  
  client.flush();

  //  LED Control
  int value = LOW;


  if (request.indexOf("/blueLED=ON") != -1)  {
    digitalWrite(blueLedOn, HIGH);
    analogWrite(blueLedPin, blueLevel);
    value = HIGH;
  }
  if (request.indexOf("/blueLED=OFF") != -1)  {
    digitalWrite(blueLedOn, LOW);
    value = LOW;
  }

  if (request.indexOf("/whiteLED=ON") != -1)  {
    digitalWrite(whiteLedOn, HIGH);
    analogWrite(whiteLedPin, blueLevel);
    value = HIGH;
  }
  if (request.indexOf("/whiteLED=OFF") != -1)  {
    digitalWrite(whiteLedOn, LOW);
    value = LOW;
  }

  // New Bit
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();

  client.println("<HTML>");
  client.println("<HEAD>");
  client.println("<TITLE>LED Control Module</TITLE>");
  client.println("</HEAD>");
  client.println("<BODY>");

  client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page

  client.println("Set LED LEVELS: <INPUT TYPE=TEXT NAME='LEDWHITE' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");

  client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send White LED Level'>");

  client.println("</FORM>");

  client.println("<BR>");


  // Blues
  client.print("The Time is now : ");
  client.print(ctime(&now));
  client.print("Blue Leds are now: ");

  if (blueLedPin == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("<a href=\"/blueLED=ON\"\"><button>Turn Blue Leds On </button></a>");
  client.println("<a href=\"/blueLED=OFF\"\"><button>Turn Blue Leds Off </button></a><br />");
  client.println("</html>");

  // Whites

  client.print("White Leds are now: ");

  if (whiteLedPin == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("<a href=\"/whiteLED=ON\"\"><button>Turn White Leds On </button></a>");
  client.println("<a href=\"/whiteLED=OFF\"\"><button>Turn White Leds Off </button></a><br />");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");


}
The problem is I dont get why he got me to do it this way, and I am not sure it "works" when I finally gently caress about with it enough to get it to work.

With this code I can set the value and press submit and the URL has the correct value in it. I just want that value setting to a variable, it shouldn't be hard no?

Splode
Jun 18, 2013

put some clothes on you little freak
That is a mess. I'm phone posting so I can't get the sketch I based my code around for you, but check out the ESP8266WebServer library and it's example, I used it and it's a lot less messy.

Splode fucked around with this message at 20:41 on Oct 26, 2017

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
Can I cheat? I just need to grab the 3 digits after the = and make that equal to whiteLevel

if (request.startsWith("/whiteLevel=") != -1) {
Serial.println("WHITE LEVEL SET ");
Serial.println(whiteLevel);
analogWrite(whiteLed, whiteLevel);
}


The URL looks like
http://192.168.1.150/?LEDWHITE=100&submit=Send+White+LED+Level

Splode
Jun 18, 2013

put some clothes on you little freak
There's a nice way to do that, I had the user set the temperature that way, hang on...

Fake edit:


code:

void updateSetTemp() {
  if (server.hasArg("setTempArg")){
    setTemp = server.arg("setTempArg").toInt();
    Serial.print("New Set Temperature: ");
    Serial.println(setTemp);
  }
}

This requires you to set up a form on your html page

code:

pageControls += "<form action = \"\" method=\"post\"> Set Temperature: <br> <input type=\"text\" name=\"setTempArg\" value = \"";
  pageControls += (String)setTemp;
  pageControls += "\"><input type=\"submit\" value=\"Set\"></form></p>";

My web page was set up in the code as a bun of strings that I could gently caress with depending on what the user did

Moey
Oct 22, 2010

I LIKE TO MOVE IT

thegasman2000 posted:


const char* ssid = "PrettyFlyForAWifi";


I wonder how many people have this same SSID. Someone near me has it as well.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
'class WiFiServer' has no member named 'hasArg'

:/ Never ending

Splode
Jun 18, 2013

put some clothes on you little freak

thegasman2000 posted:

'class WiFiServer' has no member named 'hasArg'

:/ Never ending

Are you using this library?

https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer

Use it, check out the examples

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
Not sure what's going on here:



There are two DS1307s, one with a crystal already installed I think (on the left), what's the DS pin for ?

Here 's a general C question, I scrapped a bunch of tide predictions from a website, so far I formatted them in a rudimentary CSV format:

code:
2017,11,21,00,18,low,79
2017,11,21,06,05,high,79
2017,11,21,12,37,low,76
2017,11,21,18,20,high,76
(That's year, month, day, hour, minute, tide type, strength)

I'm going to want to go look up a date and read the associated time and tide values.
Generally speaking, what's the cleanest/least headachy way to go about this on a limited system ?

I'll probably replace the high and low fields with a numeric value at one point but that's my only idea.
I plan to store those on a small SD card or any compatible medium that will support a 40kb text file.

Rexxed
May 1, 2010

Dis is amazing!
I gotta try dis!

unpacked robinhood posted:

Not sure what's going on here:



There are two DS1307s, one with a crystal already installed I think (on the left), what's the DS pin for ?

Here 's a general C question, I scrapped a bunch of tide predictions from a website, so far I formatted them in a rudimentary CSV format:

code:
2017,11,21,00,18,low,79
2017,11,21,06,05,high,79
2017,11,21,12,37,low,76
2017,11,21,18,20,high,76
(That's year, month, day, hour, minute, tide type, strength)

I'm going to want to go look up a date and read the associated time and tide values.
Generally speaking, what's the cleanest/least headachy way to go about this on a limited system ?

I'll probably replace the high and low fields with a numeric value at one point but that's my only idea.
I plan to store those on a small SD card or any compatible medium that will support a 40kb text file.

I haven't used one of those but apparently DS is a temperature sensor output:
http://www.hobbyist.co.nz/?q=real_time_clock

GlyphGryph
Jun 23, 2013

Down came the glitches and burned us in ditches and we slept after eating our dead.
So I've realized that shopping for wire connectors is very hard when you don't actually know the name for the various wire connectors. Unfortunately, my in person electronics shop isn't any longer, so my continuing ignorance ain't gonna work anymore.

What do you actually call the following connectors so I can buy them online properly?

These are the two I need right now. Basic, I know, but no idea what they are actually called and I've finally run through my supply of both.





Any additional semi-common connector names would be great! only one I can ever remember is "screw terminal" and there's actually a bunch of different variants for that. And those aren't very useful for the "need to connect to actual prongs of some sort" place I'm stuck in right now.

I've also got a button I need to hook up to that has prongs like:
pre:
  | | |
|       |
and which has the copper whatever-its-called connectors in the first picture above and have no idea if there's a better connector to fit something like that but it would be nice.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
The first one is a "blade" connector, maybe a Faston? https://en.wikipedia.org/wiki/Electrical_connector#Blade_connector

e: The second may be a Molex crimp housing?

ynohtna fucked around with this message at 15:18 on Oct 29, 2017

Dynamite Dog
Dec 12, 2012

It's a Molex KK connector

E - https://www.digikey.com/catalog/en/partgroup/kk-series/25872

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
Yo use wago surface mount lever connectors they own hard

Dynamite Dog
Dec 12, 2012

Yes, wago 222 connecters and the like are good too but probably more expensive than molex.

Common pin types you'll hit will probably be some kind of Molex (KK, Minifit, minifit jr, microfit) and JST.

Sagebrush
Feb 26, 2012

Micro-fit are my favorite small connector

rawrr
Jul 28, 2007
Does anyone have experience with/thoughts about the Wago 256 (cage clamp) spring connectors? How robust are they compared to the Faston blade connectors?

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

unpacked robinhood posted:

Here 's a general C question, I scrapped a bunch of tide predictions from a website, so far I formatted them in a rudimentary CSV format:

code:
2017,11,21,00,18,low,79
2017,11,21,06,05,high,79
2017,11,21,12,37,low,76
2017,11,21,18,20,high,76
(That's year, month, day, hour, minute, tide type, strength)

I'm going to want to go look up a date and read the associated time and tide values.
Generally speaking, what's the cleanest/least headachy way to go about this on a limited system ?

I'll probably replace the high and low fields with a numeric value at one point but that's my only idea.
I plan to store those on a small SD card or any compatible medium that will support a 40kb text file.

How many records are there? If it can fit in ROM, I would do that, so you don't have to deal with the SD card.

If you have the same amount of data for each day, looking a day up is easy. Just calculate (current day - start day) * bytes-per-record and you have an index into the table. If you are missing some days, or have different amounts of data for each, you could make an index or you could binary search the data (assuming it is sorted).

Sagebrush
Feb 26, 2012

40kb is too much to fit even in an Arduino's PROGMEM, as the 328 on an Uno only has 32kb of total flash. If you've got a bigger Arduino you can certainly do it.

However, you can probably save a ton of space by compressing your date to a smaller format. Your plain text file currently uses 24 bytes per line of data. I suggest taking the 32-bit Unix timestamp for each entry and combining it with a single byte that concatenates high or low tide and tide strength. For instance you could use the lower seven bits to record tide strength from 0 to 128, and the upper bit for high or low.

The end result of that would be 5 bites for each entry, so you'd be down to less than a quarter of your original file size. Store that in a PROGMEM array and you've still got 22 kilobytes left for your program.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
So I have 2 input fields on a web interface. I use String request = client.readStringUntil('\r'); to get the url from the get form and it works great until I try the second field. I am guessing the problem is that the variable request isn't being "cleared". My code looks like this:

code:

#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <time.h>
 
// Wifi Settings
const char* ssid = "PrettyFlyForAWifi";
const char* password = "reidbuck";
WiFiServer server(80);
 
// Time Settings
int timezone = 3;
int dst = 0;
 
int blueLevel = 1000;
int whiteLevel = 1000;
 
 
 
 
void setup() {
  Serial.begin(115200);
  delay(1);
 
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
 
  // Read the first line of the request
 
  
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Web Page Bit
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();
 
  client.println("<HTML>");
  client.println("<HEAD>");
  client.println("<TITLE>LED Control Module</TITLE>");
  client.println("</HEAD>");
  client.println("<BODY>");
  client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
  client.println("Set White Led Level: <INPUT TYPE=TEXT NAME='LEDWHITE' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");
  client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send White LED Level'>");
  client.println("</FORM>");
  client.println("<BR>");
  client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page
  client.println("Set Blue Level: <INPUT TYPE=NUMBER NAME='LEDBLUE' VALUE='' SIZE='25' MAXLENGTH='50'><BR>");
  client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send Blue LED Level'>");
  client.println("</FORM>");
  client.println("<BR>");
  client.println("</BODY>");


  if (request.startsWith("/LEDWHITE=") != -1) {
    request = request.substring(15,19);
    whiteLevel = request.toInt();
    Serial.print("WHITE LEVEL SET TO = ");
    Serial.println(whiteLevel);
    Serial.println("Flush the variable Request");
    request = "Flushed";
  }

   if (request.startsWith("/LEDBLUE=") != -1) {
    request = request.substring(11,15);
    blueLevel = request.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
    Serial.println("Flush the variable Request");
    request = "Flushed";
  }

 Serial.println(whiteLevel);
 Serial.println(blueLevel);
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

  
 
}

I tried setting the variable to something else within the first IF statement but no dice...

unpacked robinhood
Feb 18, 2013

by Fluffdaddy

Sagebrush posted:

I suggest taking the 32-bit Unix timestamp for each entry and combining it with a single byte that concatenates high or low tide and tide strength. For instance you could use the lower seven bits to record tide strength from 0 to 128, and the upper bit for high or low.

The end result of that would be 5 bites for each entry, so you'd be down to less than a quarter of your original file size. Store that in a PROGMEM array and you've still got 22 kilobytes left for your program.

Thanks.
In C it would be two arrays of identical sizes, one with 32 bit values, the other a byte wide, accessed with the same index ?


I like the idea of having an SD card in the back instead of removing the uC each year to flash fresh data, but it's really not a huge concern, and functionally makes almost no difference.

taqueso posted:

How many records are there? If it can fit in ROM, I would do that, so you don't have to deal with the SD card.

If you have the same amount of data for each day, looking a day up is easy. Just calculate (current day - start day) * bytes-per-record and you have an index into the table. If you are missing some days, or have different amounts of data for each, you could make an index or you could binary search the data (assuming it is sorted).

My current file is around 1300 lines (approx. a year worth), each line is a day, a different hour and data for the same day occupies a new line.
A day can have 3 or 4 records (spread over 3 or 4 lines) so I can't scroll a fixed number of lines to lookup a specific day.

I can use binary search since the lines are ordered by increasing timestamps (using Sagebrush's suggestion), thanks for the idea.

e: For example the atmega88 has 8kb of program memory.
Assuming 5 bytes wide lines, I can store 800 lines (around 6 months of data) and still have 50% for the program, correct ?
(8x8x1024)-(800x40)

unpacked robinhood fucked around with this message at 09:05 on Nov 1, 2017

spiritual bypass
Feb 19, 2008

Grimey Drawer
Is there any way of running Arduino C programs locally? I'd like to build a test suite to run my functions locally instead of just sending them straight to the device without knowing their behaviors.

ElCondemn
Aug 7, 2005


rt4 posted:

Is there any way of running Arduino C programs locally? I'd like to build a test suite to run my functions locally instead of just sending them straight to the device without knowing their behaviors.

You can compile locally but Arduino applications aren’t designed to run the way a normal application does on your PC. Maybe it’s doable but I haven’t seen anything that just let’s you compile and run like a normal executable.

What you can do, and what I’d suggest, is just write a library in C and import the library into your arduino sketch when you’re ready to run it. You’ll have to implement the library for each environment but you can guarantee the logic will be the same.

spiritual bypass
Feb 19, 2008

Grimey Drawer
That sounds good. What I'm trying to get is a clean separation between the code that calculates what should happen (declarative) and the code that tells the Arduino to execute it (imperative). Not too worried about testing the Arduino-specific stuff.

Setting aside issues like number sizing, most functions I write that don't use Arduino-specific should compile and run equally well with gcc as they do on the device?

Sagebrush
Feb 26, 2012

Arduino C is regular C. (C++11, I believe). However, microcontroller code in general is often very hardware specific. Arduino does its best to abstract some of the things like GPIO and ADC reading (which require that you access specific memory registers that will differ from one chip to another) so that the same code works on a variety of different boards, but it still doesn't make sense to run code with an analogRead(12) on your PC, which doesn't have a pin 12 or an ADC connected to it. If all your code is doing is math and serial printing, or other stuff that doesn't rely on any microcontroller specific hardware features, then yeah, you could port it to run on your computer with minimal changes.

To do what you're asking, you essentially need a simulator that creates a virtual AVR and simulates the code step by step.

Trauma Dog 3000
Aug 30, 2017

by SA Support Robot

Sagebrush posted:

Arduino C is regular C. (C++11, I believe). However, microcontroller code in general is often very hardware specific. Arduino does its best to abstract some of the things like GPIO and ADC reading (which require that you access specific memory registers that will differ from one chip to another) so that the same code works on a variety of different boards, but it still doesn't make sense to run code with an analogRead(12) on your PC, which doesn't have a pin 12 or an ADC connected to it. If all your code is doing is math and serial printing, or other stuff that doesn't rely on any microcontroller specific hardware features, then yeah, you could port it to run on your computer with minimal changes.

To do what you're asking, you essentially need a simulator that creates a virtual AVR and simulates the code step by step.

you'd probably do better to just run the tests on the device

Splode
Jun 18, 2013

put some clothes on you little freak
I often have a second arduino that I use as a development device for stuff like that (where I need to test higher level logic or comms).

It's always a good idea to just have piles of arduino compatible microcontroller boards lying around.

Dark Off
Aug 14, 2015




rt4 posted:

Is there any way of running Arduino C programs locally? I'd like to build a test suite to run my functions locally instead of just sending them straight to the device without knowing their behaviors.

https://www.tinkercad.com/
tinkercad lets you simulate arduino code on its circuit playground.

Adbot
ADBOT LOVES YOU

Rat Poisson
Nov 6, 2010

unpacked robinhood posted:

I like the idea of having an SD card in the back instead of removing the uC each year to flash fresh data, but it's really not a huge concern, and functionally makes almost no difference.

My current file is around 1300 lines (approx. a year worth), each line is a day, a different hour and data for the same day occupies a new line.


Are you doing this for a US-based location? Is there a library in this collection: https://github.com/millerlp/Tide_calculator close to your site? If so, those libraries are set to make tide predictions through 2024, by just supplying a date and time.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply