#help-with-arduino

1 messages · Page 86 of 1

paper mist
#

can i do that in software on a pro micro?

flint smelt
#

digitalWrite(pin, LOW)

paper mist
#

thanks

flint smelt
#

No problem

unborn frost
#

what is the best Arduino for low power aka deep sleep?

wooden wagon
#

I accidentally had a sneaky line ‘‘delay(100);‘‘

#

Getting rid of that gives a nice solid image again

fading abyss
elder hare
#

In the FastLED fastpin_esp32.h

they mention

_FL_DEFPIN(21); // Works, but note that GPIO21 is I2C SDA
_FL_DEFPIN(22); // Works, but note that GPIO22 is I2C SCL

that's just to say that if you use I2C dont use these pins for LED Strips or?

rough torrent
#

Is 25 kilobytes / second too much for an Adafruit AirLift Featherwing? Or is the SPI bus the throttle? Or is the SAMD51 the slow part? (Please ping if you answer)

safe shell
#

@rough torrent I'm not clear on what the graph is measuring. SPI runs at 8MHz for the FeatherWing.

gray holly
#

I'm a noob, and I'm trying to upload a file to my arduino nano. It is correctly set as such in the boards menu.


In file included from /home/ryan/Desktop/S7ripClock_BE_v5/S7ripClock_BE_v5.ino:6:0:
/home/ryan/Arduino/libraries/DS3232RTC-master/DS3232RTC.h:25:10: fatal error: TimeLib.h: No such file or directory
 #include <TimeLib.h> // http://playground.arduino.cc/Code/time
          ^~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.```
rough torrent
cedar mountain
#

@gray holly It looks like you need to download and install the time library from the URL in the comment there.

gray holly
#

Ah ok

#

/home/ryan/Arduino/libraries/DS3232RTC-master/DS3232RTC.cpp:8:10: fatal error: Stdint.h: No such file or directory
 #include <Stdint.h>
          ^~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
#

Now, there's a different error

#

Is stdint.h a library?

#

I am able to upload an empty sketch, so it's a sketch or library issue

cedar mountain
#

It's a standard C library, though normally it would be uncapitalized, so that's a bit weird to see.

gray holly
#

What should I do to fix that?

rough torrent
# safe shell Wi-Fi should be able to run faster than that, assuming good signal, server, etc....

Here's some sample output from the serial monitor:

Attempting to connect to SSID: **************
Connected to wifi
SSID: **************
IP Address: 192.168.1.41
Signal strength (RSSI): -45 dBm
Starting connection to server...
...                    <-- Bunch of garbage output that's not related
Setting timer sample rate to: 44100
Received 13346 bytes in 1 second!
Received 26387 bytes in 1 second!
Received 24491 bytes in 1 second!
Received 23251 bytes in 1 second!
Received 23872 bytes in 1 second!
Received 23237 bytes in 1 second!
Received 25760 bytes in 1 second!
Received 22610 bytes in 1 second!
Received 26387 bytes in 1 second!
Received 24498 bytes in 1 second!
Received 24499 bytes in 1 second!
Received 25752 bytes in 1 second!
Received 27007 bytes in 1 second!
Received 24498 bytes in 1 second!
Received 23245 bytes in 1 second!
Received 23749 bytes in 1 second!
Received 22106 bytes in 1 second!
Received 24498 bytes in 1 second!
Received 10852 bytes in 1 second!
Received 0 bytes in 1 second!        <-- Received nothing
Received 0 bytes in 1 second!
Received 0 bytes in 1 second!
Received 25583 bytes in 1 second!
Received 23871 bytes in 1 second!
Received 24418 bytes in 1 second!
Received 25833 bytes in 1 second!
Received 25126 bytes in 1 second!
Received 25761 bytes in 1 second!
Received 22609 bytes in 1 second!
Received 26380 bytes in 1 second!
Received 23871 bytes in 1 second!
Received 24499 bytes in 1 second!
Received 25126 bytes in 1 second!
Received 23871 bytes in 1 second!
Received 25753 bytes in 1 second!
Received 23244 bytes in 1 second!
Received 23872 bytes in 1 second!
Received 25126 bytes in 1 second!
...                                    <-- More output
cedar mountain
#

Is this code you've written, code you've downloaded from a well-known source, or some random piece of code you found online that may or may not actually be supposed to work? 😉

gray holly
#

It's code from the person who made the clock project

#

It was recently uploaded and there's a video of it working on a device exactly like mine

stuck coral
gray holly
#

Step 9: Arduino Sketch
The software sketch is at version 5. This is because it is very close to the one I've been using for some of my other projects, so I didn't want to confuse this because of the redesigned "hardware" around it...

Basic usage:

Button A: Select brightness
Button A (long press): Switch color mode (per digit/per led)

Button B: Select color palette
Button B (long press): Switch 12h / 24h mode

Button A + B: Enter setup
While in Setup: ButtonB -> Increase +1, ButtonA -> Accept/Next

#

So what should I do about stdint

cedar mountain
#

The problem is coming from the DS3232RTC library, so you might want to see if there's a different version of that available?

gray holly
#

hmm

#

I'll try it from a mirror

rough torrent
gray holly
#

How do I delete a library?

rough torrent
stuck coral
wooden wagon
#

how are you supposed to make connections to a pro micro board? i find soldering wire into each hole to be incredibly difficult

stuck coral
#

And use jumpers or a breadboard

pulsar junco
#

female headers are useful for this but hard to find sometimes

stuck coral
#

Eh, I think male headers gives you more options, a giant pack of jumpers is cheap

pulsar junco
#

well that's not true, stackable female headers can be hard to find

wooden wagon
#

i looked at this, but it added too much height to my builds. im using them for button boxes and things, where compactness is key

stuck coral
#

@rough torrent if you limit your send rate, does it still break up a ton, or less

#

Because you could also be filling your buffer

rough torrent
stuck coral
#

On the ESP32?

#

Oh I see, still

#

In that case, I go back to, wifi is unreliable, and crap

rough torrent
#

Well, I didn't code it to send any data besides starting the connection to the server

stuck coral
#

UDP or TCP?

rough torrent
#

Hmmmm...I should be using TCP.

#

I can't tell :/

safe shell
#

memory buffers are limited. what's driving the once-per-second timing?

stuck coral
#

You know what, I bet anecdata got it.

#

An ARQ protocol would probably be best here but I dont know of any implementations for the ESP

rough torrent
#

I'm not explicitly requesting to use UDP and I'm using SSL so I think I'm using TCP

safe shell
#

constant bitrate MP3s?

stuck coral
#

Increasing the buffer is probably the easiest solution, and hope the SPI reads catch up

#

Oh, lol, how about no SSL?

#

How does that go?

rough torrent
#

I can't not use SSL - the server I'm connecting to uses HTTPS

safe shell
#

what's doing the MP3 decoding?

rough torrent
#

And I just restarted my WiFi extender and it's gotten better

#

Nope, never mind

stuck coral
#

Could you answer anecdatas question? Are you decoding something right now? And I shouldnt have butted in, I thought you were doing a simple socket connection, I should have read more into this, lol

rough torrent
safe shell
#

I'm just guessing @stuck coral, teamwork ftw!

stuck coral
#

Do you happen to know @safe shell if with the ESP32 as a co processor are you able to pull debug info?

#

I assume not

safe shell
#

yes, you can set esp.debug = 1,2, or 3 iirc

#

3 and you'll probably kill the uart tho

rough torrent
#

lolololol

stuck coral
#

Were using SPI, just bump the clock up shell be right

safe shell
#

wifinina inits SPI with 8MHz, could try a little more, hope your connections are solid. But I suspect this will take some fine-tuning of each element in the pipeline

stuck coral
#

Pft

#

ESP32 can go up to 80 reliably from what I hear

#

And the SAMD is no slouch

#

Nevermind, 40Mhz lol

#

And this is on a PCB, probably with no other wires

safe shell
#

if not soldered, feather connections can be flaky, those stacked header wires are a bit thin

rough torrent
#

So I should try like 16 first?

#

The Featherwing is directly connected to the headers, but my soldering isn't the best.

safe shell
#

I'm not convinced that's the key, there's still quite a gap between 25KBytes/sec and 8MHz

rough torrent
#

I was thinking about adding a buffer of some sorts - was looking into the CirculerBuffer library

stuck coral
#

Yes, I just want debug info to rule ESP connection issues out

rough torrent
#

Do I literally just put esp.debug = 2 somewhere in setup()?

#

Because I don't have an esp object defined.

safe shell
#

oh, sorry, my brain is in CircuitPython still, I'll check...

#

d'oh, there might not be debug in the Arduino lib

rough torrent
#

Yea, I don't any docs for the Arduino library - is there a Github repo for Adafruit's WiFiNINA library somewhere?

#

Maybe they have a link there.

safe shell
#

it's probably an Adafruit fork addition nope, it's in the orig Arduino

rough torrent
#

If this was CircuitPython, we probably could have just done like from WiFiNINA.utility import debug lol

safe shell
#

what's the source material? ```Best practice for producing playable MP3 files

Encode at constant 40kbps with a sample rate of 44,100 kHz
Stereo only```

rough torrent
#

Dang, WiFi.config would have been the perfect place to include a debug parameter 😦

#

Huh, seems to be working completely fine now - getting an RSSI of -45 to -60

#

Maybe just a connection issue.

#

And the RSSI doesn't fluctuate (well, it does change but not drastically) when I get down to 0 bytes/sec
Thanks for the help @safe shell and @stuck coral. I got to go.

unborn frost
#

please help, I have this Arduino code:


Servo serv;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  serv.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}

void loop() {
  Serial.println("Loop");
  serv.write(0);
  delay(1200);
  Serial.println("60");
  serv.write(60);
  delay(700);
  Serial.println("120");
  serv.write(120);
  delay(700);
  Serial.println("180");
  serv.write(180);
  delay(700);
}``` but my servo acts sporadically, sometimes it does the motion perfectly, other times it does half then other times it will just sit there and do nothing. 
Ive -changed arduino boards (both nanos)
-used external power source
-reset
no sure what else to try. I did push it a little far earlier today not sure if that has any effect. Any help would be really helpful. thanks
reef ravine
unborn frost
#

i did, it did the same kind of thing

reef ravine
#

perhaps the servo is damaged

unborn frost
#

is there any way to confirm that?

reef ravine
#

i would expect that example program should run smoothly. do you have another servo?

unborn frost
#

no, ordered this special for a project

reef ravine
#

you could try a single serv.write(<0-180>); in setup and see if there is a "dead spot" in the rotation at a certain position value

unborn frost
#

ok, will try that. thanks

rough torrent
pine bramble
pine bramble
reef ravine
#

missing ground on right 2 LEDs, whats the thing in the middle?

pine bramble
#

The light sensor?

#

Oh whoops I didn't catch that

reef ravine
#

the light sensor is a cds cell?

pine bramble
#

It's an Ambient light sensor (Phototransistor) . I'm not sure if I know what cds means haha

reef ravine
#

just wondered if its output is analog or digital

obtuse spruce
#

I tend to just plug the power decoupling capacitor directly between the + and - rails at the bottom there... and just take the power for the servo from nearby pins on those rails. No need to pull it out into the middle of the breadboard like that... and which side of the cap you connect to the servo (1st vs. 2nd image) makes no difference.

cedar mountain
#

Cadmium selenide, I think. Nope, sulfide, woops.

pine bramble
#

I put it as input, in my code, though I'm not sure.

reef ravine
#

cadmium di-sulfide iirc

pine bramble
#

I have no clue what that is haha... @obtuse spruce Hello again! Would it have the same outcome if I change it?

reef ravine
pine bramble
#

oh wait I forgot something! Going to repost the picture real quick.

reef ravine
#

see how the horizontal rails top and bottom are equivalent?

#

you could for instance route all the ground connections to one side, +v connections to the other side

deep hazel
#

i've not ventured out beyond, well... printf and blinking LEDs for debugging... lol, curious about how much nicer programming/debugging my growing flock of mcus could be if i had something like that instead of just a usb serial connection

cedar mountain
#

Debugging is definitely a different experience with that sort of tool. Code breakpoints and memory breakpoints are quite handy. I wouldn't necessarily say it's "nicer", but it does allow you to tackle problems of more complexity.

deep hazel
#

yeah i've already ran into a few things where being able to get a better look into things would have made debugging some weird edge case so much easier and quicker, would something like that integrate nicely with Arduino IDE or is it far more useful when paired with something like Atmel Studio?

cedar mountain
#

Not sure there... I'm unfamiliar with the Arduino IDE, but other IDEs like STM32Cube, Keil, Atmel Studio, etc. should be able to use it.

deep hazel
#

another thing i'm thinking it could be useful for is reprogramming some Seesaw breakout boards to change what pins do what... not to mention i wouldn't mind moving away from Arduino IDE eventually, though a j-link probably isn't required for other IDEs

#

i was bit hard by the microcontroller bug this year and coming from IDEs like CLion, Arduino IDE is... moody and lacking, comparatively, and it feels like i'm having to fight with it more than i should

cedar mountain
#

Don't feel guilty about outgrowing it. 😉

deep hazel
#

ehh what the heck, it's only $20 and there's a million things out now running some sort of Cortext-M with SWD pads to it on the boards, two lunches worth of cash is well worth the learning that'll be had, plus breaking the reliance on a functional bootloader and usb port

cedar mountain
#

Haha, indeed. The full commercial J-Link is like $600, so be happy for the EDU option...

deep hazel
#

that's exactly why i've never really worked with jtag/swd stuff before lol, always seemed so expensive to get a proper one

#

but $20... that's a lot more in the "i'll give it a shot" realm instead of the "the accounting department will cut you a check for it" realm

cedar mountain
#

Yep, I've found it hard to justify a Segger myself, though there are cheaper options, like STLinks, the FTDI-based JTAG adapters, and other third-party tools. There's nothing inherently expensive about JTAG.

elder hare
#

How to get this doc["colorGradient"]

JsonArray array = doc["colorGradient"].as<JsonArray>();
for(JsonVariant v : array) {
    Serial.println(v.as<byte>());   
}

into this byte array?

byte m_Gradient[256] = { 0 };
vivid rock
#

@deep hazel I have used the segger mini for flashing bootloader to bare metal samd chips. works very well with Atmel studio

#

haven't used it for debugging yet

#

as for IDE - there is also platformIO; have you tried it?

trim hatch
#

I'm trying to have two Arduino's communicate with each other through I2C. I'm trying to send a string from the transmitter to the receiver, and have the receiver receive it and put it into a SD card. The if(Wire.available() > 0) doesn't execute either, and I'm not sure if it's a problem with the transmitter or receiver or hardware. For hardware I have A4 - > A4, A5 -> A5, and GND to GND. I'm not sure why the communication doesn't get received or transmitted. Here is the code that I am running -

Transmitter: https://pastebin.com/9f8z5xXb
Receiver: https://pastebin.com/ksgLNseF

rough torrent
#

And it adds another number to display, which makes it cooler 😎

rough torrent
#

Also, how can I see how much static memory I've allocated? (Using an SAMD51) I want to make my buffer as big as possible (maybe 64KB?)

trim hatch
#

Also another question I have is how can I add a timestamp to an SD card without using a RTC

rough torrent
#

You could just use millis() but that's kinda stupid, because if the Arduino reboots, then it gets sent back to zero. And it will overflow in around 52 days?

#

You could use some WiFI hardware, connect to an NTP server

#

But a RTC is your best bet if you don't have an internet connection for your Arduinos.

vivid rock
#

@trim hatch what exact boards are you using? are these Unos?

#

have you added pullups on SDA and SCL lines

trim hatch
#

one uno and one nano

#

do I need pull ups on both or just SDA?

vivid rock
#

on both

#

it is recommended to use 2-10k pullups

trim hatch
#

if that doesn't work what should I try

#

is there anything wrong with the code?

vivid rock
#

putting wire.read() inside ISR is not a good idea

#

ISRs should be executed very quickly, since during execution of ISR other interrupts are blocked

trim hatch
#

how come?

rough torrent
#

ISRs should run as quick as possible

#

Even serial printing is discouraged inside an ISR

vivid rock
#

lets do one thing at a time - first add pullups, then test basic i2c connection using the code fro arduino wire example

trim hatch
#

then how do I use an interrupt to read from wire?

#

I added the pullups, it didn't make any different

vivid rock
trim hatch
#

I tried that a couple days ago it also made no difference

#

it should be a hardware issue

vivid rock
#

in any case - first let us get the basic example working, so forget about the sd card and isrs

trim hatch
#

alright

vivid rock
#

for hardware, pullups are must

#

and - did you check which pins are sda and scl on nano?

trim hatch
#

yes A4 and A5

#

A5 - SDA, A4 - SCL

#

as far as I know

vivid rock
#

there are several variations of nano... is it a classic 5v one?

trim hatch
#

yeah

#

it's a regular Atmega382p

vivid rock
#

ok

reef ravine
vivid rock
#

can you test the basic master/slave example from arduino wire reference page?

trim hatch
#

I'm doing that right now

vivid rock
#

wow... mini usb port. Haven't seen it in a while

trim hatch
#

I tried it and it didn't work

reef ravine
#

that's why i need half a dozen "standard" USB cables 🙂

vivid rock
#

"good thing about standards is that there are so many to choose from"

trim hatch
#

yeah mini usb is used on a lot of ftdi stuff too

#

right now it pretty much just does nothing

vivid rock
#

if the basic example didn't work, it looks like hardware issue.. how long are the wires? and what value pullups did you use?

trim hatch
#

i used 10k pullups

#

and like pretty long wires

#

maybe 5-7 inch wires

vivid rock
#

i2c is flaky with long wires, but 5 in shouldn't be a problem

trim hatch
#

what about 7?

#

or possibly 8?

vivid rock
#

if you have 3.3 k resistors, you can use that, but i doubt it will make much difference

#

no, anything under 1ft should be ok

trim hatch
#

i only have 1k and 10k at the moment

#

so that's pretty much all I could use

#

A4 is suppose to go to A4 right?

#

and A5 to A5?

vivid rock
#

yes

#

sda to sda, sclto scl

trim hatch
#

what else can I try

vivid rock
#

stupid question - did you put #include <Wire.h> in your code?

trim hatch
#

lol

#

yeah

#

I don't think I can even upload it without that

vivid rock
#

you never know ... people sometimes make really silly mistakes - myself included

trim hatch
#

yeah it's happened to me before

#

a lot

#

could it be related to the length of the wires?

#

that's something I'm pretty much considering the most

vivid rock
#

ok. I am out of ideas at the moment, sadly

trim hatch
#

that's alright, thanks for the help

#

also while you're here

#

is there anyway to add a timestamp programatically

#

without a rtc

#

I want to timestamp my sd card

vivid rock
#

I dont think i can add to what Ckiyu wrote above

#

without rtc, you can only use millis()

#

but that only gives you time since reset

trim hatch
#

yeah I guess

#

can you use software serial with an rtc?

#

or wait nvm

#

anyway thanks again for your help

vivid rock
trim hatch
#

is there any serial rtc?

#

I kinda can't use i2c coz I'm using up all the buses

reef ravine
#

Google up the DATE and TIME macros

vivid rock
#

you can connect more than one slave device to same i2c bus

reef ravine
#

two underscores before and after DATE and TIME

trim hatch
#

huh, anyway I prefer Serial stuff over i2c in general

#

why @reef ravine

#

i've heard of DATE and TIME

#

in c++

reef ravine
#

but nvm, it'll only give the time & date the program was compiled

trim hatch
#

thanks for the suggestion

rough torrent
trim hatch
#

well I have 2 arduinos

#

on arduino 1 I'm using serial already for a transceiver

#

and I don't have any more Serial ports on that

rough torrent
#

oh ok

trim hatch
#

i do have a serial port on arduino 2 though

#

so I can use that

rough torrent
#

I was gonna recommend software serial then but you would have to run it at like 300BPS

trim hatch
#

yeah

#

I'm using 115200

#

and that doesn't work well

#

software serial is okay with 9600 baud

#

i just don't prefer it in general

rough torrent
#

I can understand lol

trim hatch
#

it's too much effort to get it set up

rough torrent
#

I mean, software serial is just 3 wires - TX, RX, and GND

#

and it works just like a regular serial port

#

but much slower

#

and less reliable

trim hatch
#

doesn't that answer my question? lol

#

I also use a lot of communication stuff

#

that requires high baud rates

rough torrent
#

Ah yea don't use SS for that then

#

lol

trim hatch
#

I tried it out a couple days ago with a neo6m gps

#

and I found out the hardway that it doesn't work with high baud rates

#

I just ended up using Serial1

#

because I had an arduino mega

#

for the gps

pine bramble
obtuse spruce
#

@elder hare - did you get it sorted, or do you still need help with that array?

elder hare
#

realy need help :/ been stuck at this for hours

obtuse spruce
#
static const int m_GradientSize = 256;
byte m_Gradient[m_GradientSize] = { 0 };
...
JsonArray array = doc["colorGradient"].as<JsonArray>();
int i = 0;
for(JsonVariant v : array) {
    if (i == m_GradientSize) break;
    m_Gradient[i++] = v.as<byte>();   
}
#

@pine bramble - Let's take this code one step at a time, okay?

#
int piezoPin = 7;
int LED1 = 8;
int LED2 = 9;
int LED3 = 10;
int ServoMotor = 11;
int photoTrans = 12;
int pushButton = 13;
int potpin = A0;
int LED[] = {LED1, LED2, LED3};

On these lines, you are giving nice names to pin numbers, and creating a fixed list of LED pins. You don't expect these values to ever change, right? For example... LED1 is _always 8, and will never change while the program is running, right?

#

@elder hare - there ya go -- and don't miss the quick fix I just made (m_Gardient[i++] = ...)

elder hare
#

@obtuse spruce everything is just 0 :S

#

@obtuse spruce am i printing it wrong?

    if (doc["colorGradient"])
    {
        JsonArray array = doc["colorGradient"].as<JsonArray>();
        int i = 0;
        for(JsonVariant v : array)
        {
            if (i == 256) break;
                m_Gradient[i++] = v.as<byte>();
                Serial.println(m_Gradient[i++]);
        }
    }
obtuse spruce
#

you are incrementing i when you are printing it!

#

Notice that after the assignment, i is left pointing to the next location. i++ means "use i and then, after this statement, but before the next, increment it.

elder hare
#

oh yea, stupid me

obtuse spruce
#
                auto x = v.as<byte>();
                m_Gradient[i++] = x;
                Serial.println(x);

is how I'd write that.

#

And yes, iterating through multiple structures at once is a weak point in C++!

elder hare
#

@obtuse spruce check this out
Qt Side of things

void Gradient::packGradient()
{
    // Always clear the QJsonArray befor resetting it!
    m_PaletteArray = QJsonArray();

    // Loop the _gradient and insert each point into the QJsonArray
    for (const auto &point : qAsConst(_gradient))
    {
        m_PaletteArray << round(point.stop * 255) << point.color.red() << point.color.green() << point.color.blue();
    }
}

This outputs

QJsonArray([0,255,255,255,116,0,0,0,255,0,0,0])

Then i send this via socket like this to the microcontroller ESP32

socket.sendCommandStrip(QString("colorGradient"), ui->L_GradientDisplay->getGradient());

ESP32 Microcontroller side of things
Class Header file

    private:
        // Gradient Color
        byte m_Gradient[256] = { 0,0,0,0,255,0,0,0 };

    public:
        void setGradient(byte gradientIn[256]);

Class Cpp File

void StripSettings::setGradient(byte gradientIn[])
{
    for (int i= 0; i < 256; i++) {
        m_Gradient[i]= gradientIn[i];
    }
}

MySocket.cpp

    if (doc["colorGradient"])
    {
        JsonArray array = doc["colorGradient"].as<JsonArray>();
        for(JsonVariant v : array)
        {
            if (i == 256) break;
                auto x = v.as<byte>();
                m_Gradient[i++] = x;
        }

        //Strips[m_selectedStrip]->setGradient();
    }

How can i put the doc["colorGradient"] array into m_Gradient[256] this array via the class setter function

obtuse spruce
#

just define a local byte array, and then call it. Here, like this:

#
    if (doc["colorGradient"])
    {
        JsonArray array = doc["colorGradient"].as<JsonArray>();
        byte gradient[256];
        int i = 0;
        for(JsonVariant v : array)
        {
            if (i >= 256) break;
            auto x = v.as<byte>();
            gradient[i++] = x;
        }
        Strips[m_selectedStrip]->setGradient(gradient);
    }
#

Now, I don't know if you need m_gradient -- if you do (because you need that gradient outside this block of code), then just get rid of my local byte gradient , go back to using m_gradient

elder hare
#

hmm

#

maybe im doing something wrong somwhere :/

#

the gradient is not showing up on the strip

obtuse spruce
#

Which light library is this?

elder hare
#

FastLED

#

so in the order of how it goes it's

MySocket.cpp

    if (doc["colorGradient"])
    {
        JsonArray array = doc["colorGradient"].as<JsonArray>();
        byte gradient[256];
        int i = 0;
        for(JsonVariant v : array)
        {
            if (i >= 256) break;
                auto x = v.as<byte>();
                gradient[i++] = x;
        }
        Strips[m_selectedStrip]->setGradient(gradient);
    }

to -> MyFastLED.cpp (class)

void StripSettings::setGradient(byte gradientIn[])
{
    for (int i= 0; i < 256; i++) {
        this->m_Gradient[i]= gradientIn[i];
    }
}

MyFastLED.h (class)

    // Private Variables
    private:
        // Gradient Color
        byte m_Gradient[256] = { 0 };
        // My Palette
        CRGBPalette32 m_myPal = m_Gradient;

    // Private Setters
    private:
        void setGradient(byte gradientIn[256]);
obtuse spruce
#

And... m_myPal can be initialized like that? I don't see an assignment or constructor that works like that.

#

Also - you're doing a lot of work passing around low level stuff here. I'd be more likely to structure this like:

#
    if (doc["colorGradient"]) {
      Strips[m_selectedStrip]->setGradient(doc["colorGradient"].as<JsonArray>());
    }

class StripSettings {
  private:
    CRGBPalette32 m_myPal;
  public:
    void setGradient(JsonArray array);
}

void StripSettings::setGradient(JsonArray array) {
  int i = 0;
  for(JsonVariant v : array)
  {
    if (i >= 32) break;
    auto x = v.as<byte>();
    m_myPal[i++] = x;
  }
}
#

Which is to say - there is some magic of how you are choosing to interpret a JSON array of numbers as a gradient --- I'd put that as close to the gradient as possible - converting it to an array of 256 bytes (arbitrary size, yes?) - and then copying that around is just "smearing" the conversion from JSON to gradient around the code.

#

(also - there really is no value in C++ to having private setters that are just wholesale copying.... just make the member variable public.)

#

BUT - I still don't know how you intend to turn that array into a gradient. The code above is not right, I'm sure

#

QJsonArray([0,255,255,255,116,0,0,0,255,0,0,0]) --- Do you mean for this to be "#ffffff at position 0, ramp to #000000 at position 116, then stay at #000000 through position 255" ??

#

If so - you are looking at building an array of 256 CRGB values - and CRGBPalette32 will not do that - it is a explicitly a gradient of 32 values. And can't be set arbitrarily.

#

There are tools in FastCGI to help you with this. You'll want fill_gradient_RGB - but you'll have to roll your own on how to fill an array of colors for it.

#

And then how to push those colors out to the leds.

elder hare
#

no it reads it as

Position, R, G, B
[0,255,255,255]
obtuse spruce
#

Something like:

    if (doc["colorGradient"]) {
      Strips[m_selectedStrip]->setGradient(doc["colorGradient"].as<JsonArray>());
    }

class StripSettings {
  public:
    static const MAXLEDS = 256;
    CRGB m_theGradient[MAXLEDS];
    void setGradient(JsonArray array);
}

void StripSettings::setGradient(JsonArray array) {
  int i = 0;
  int n = array.size();
  if (n < 4) return;  // not enough for even the first color!
  
  int pStart = array[i].as<int>;
  CRGB cStart = CRGB(array[i+1].as<byte>(), array[i+2].as<byte>(), array[i+3].as<byte>());
  i += 4;
  n -= 4;

  while (n > 0) {
    int pEnd = array[i].as<int>;
    CRGB cEnd = CRGB(array[i+1].as<byte>(), array[i+2].as<byte>(), array[i+3].as<byte>());
    i += 4;
    n -= 4;
    fill_gradient_RGB(m_theGradient, pStart, cStart, pEnd, cEnd);
    pStart = pEnd;
    cStart = pEnd;
  }

  if (pStart < MAXLEDS) {
     CRGB black(0, 0, 0);
     fill_gradient_RGB(m_theGradient, pStart, cStart, MAXLEDS, black)
  }
}
#

Notice that you to do that kind of thing yourself --- CRGBPalette32 doesn't do what you need

elder hare
#

if i set this by hand

    private:
        // Gradient Color
        byte m_Gradient[256] = { 0, 255, 0, 0, 255, 0, 255, 0 };
        // My Palette
        CRGBPalette32 m_myPal = m_Gradient;

i will get a gradient on my strip from position 0 (255 red) to position 255 (255 green)

obtuse spruce
#

show me how you set that gradient on the strip? Nonetheless -- the 32 is a clue there - it only supports 32 colors in the palette... not arbitrary breakpoints along 256 (or more) LEDs.

elder hare
#

https://www.youtube.com/watch?v=Ukq0tH2Tnkc&ab_channel=ScottMarley like this only i dont store it in PROGMEM with (DEFINE_GRADIENT_PALETTE)! i just use the byte * array

In the third episode of FastLED basics, we look at palettes. Palettes are a powerful FastLED feature that will help you to create coherent patterns without too much work! We'll have a look at gradient and 16 color palettes, dealing with palettes using online tools, fadeToBlackBy, and finally look at palette blending.

GitHub link for code: https...

▶ Play video
obtuse spruce
#

sadly - gotta run - work out time...

elder hare
#

sure sure 🙂

wooden wagon
#

where should i start when making a button regonizeable as a joystick/gamepad input on windows?

leaden walrus
#

look for "HID mouse" projects

#

same general idea though

#

read joystick -> convert to HID mouse messages

#

you can also do keyboard messages

wooden wagon
#

ah that isnt quite what im looking for. im not sure what its called, but its in this menu:

#

looking at some example code, it seems like they are using keypad.h and joystick.h

leaden walrus
#

that sounds like the HID library

wooden wagon
#

i misunderstand, i see now, thanks

deep hazel
#

@vivid rock just got PlatformIO set up with CLion last night, this is gonna be nice lol, i had only heard of it before, never actually checked into it, i just figured it was another one of those "IoT cloud!!!1" things

elder hare
#

@obtuse spruce let me know when you are back 🙂

elder hare
#

is there not a method like in the Arduino IDE (where you can paste the crash log into the plugin and it tells you what the crash was) but for PlatformIO?

#

EspExceptionDecoder

#

this one

#

wait wait wait... in the consol it says Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled. - (IntegerDivideByZero) <--- is that the actual error?

gray holly
#

When trying to upload a program, I get

Arduino: 1.8.13 (Linux), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

In file included from /home/ryan/Desktop/S7ripClock_BE_v5/S7ripClock_BE_v5.ino:13:0:
/home/ryan/Arduino/libraries/FastLED-3.3.3/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.003
 #    pragma message "FastLED version 3.003.003"
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Sketch uses 15680 bytes (51%) of program storage space. Maximum is 30720 bytes.
Global variables use 915 bytes (44%) of dynamic memory, leaving 1133 bytes for local variables. Maximum is 2048 bytes.
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

avrdude: arduino_read_sig_bytes(): (a) protocol error, expect=0x10, resp=0xfc
avrdude: error reading signature data for part "ATmega328P", rc=-3
avrdude: error reading signature data, rc=-3
avrdude: error reading signature data, rc=-3



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
``` over and over
#

I have selected the correct board

normal bough
#

Hey does anyone here have experience with the MLX90393 magnetometer board? The data sheet says it should be able to go up to a sampling rate of ~500 hz but I'm only able to achieve about 90 hz using the exact settings it says should give 500 hz.

gray holly
#

I got it working, but the serial monitor just prints

⸮⸮X⸮A⸮⸮05⸮⸮    ċ⸮⸮⸮U⸮⸮⸮⸮⸮Y⸮Ո⸮*⸮⸮⸮*⸮⸮⸮"⸮⸮B™"⸮⸮"⸮F⸮⸮"⸮H⸮CĔK⸮⸮"⸮⸮⸮⸮*⸮⸮K⸮*⸮⸮⸮⸮⸮"⸮H⸮*⸮⸮O⸮*⸮⸮⸮⸮⸮"⸮⸮B⸮⸮⸮"⸮⸮⸮œk⸮⸮I⸮⸮⸮b⸮⸮ja⸮yC⸮⸮B⸮⸮⸮⸮&⸮K⸮.Bl⸮⸮Bl⸮Cl⸮Bl⸮⸮⸮K⸮⸮I⸮⸮⸮.⸮⸮*⸮⸮⸮⸮b⸮⸮ja⸮bɵ⸮⸮⸮⸮⸮⸮⸮⸮⸮~⸮H"⸮⸮K⸮⸮I⸮⸮O⸮⸮"⸮⸮⸮⸮⸮*⸮⸮⸮*⸮⸮K⸮⸮O⸮⸮*⸮⸮k⸮k⸮⸮I⸮⸮⸮⸮⸮b⸮⸮⸮⸮j⸮⸮jJ⸮j
⸮b⸮⸮⸮⸮⸮⸮⸮
⸮⸮⸮⸮⸮
⸮⸮
⸮⸮⸮⸮bɉE⸮⸮⸮⸮⸮
⸮⸮
fierce plank
gray holly
#

Where in the code is the baudrate?

fierce plank
#

Serial.begin(<baud rate>)

gray holly
#

There we go

#

Thank you

fierce plank
#

np

gray holly
#

It's supposed to control an led strip, but only one light is on and nothing else is happening

#

Is the light strip supposed to have none on or some on?

#

When plugged in to power alone

normal bough
#

Hey @leaden walrus I believe you were the one that helped me with the library a month or so ago for the MLX90393 magnetometer. Thanks again for that! Anyway with the settings I'm using the datasheet says the read data command should only take 1.84 ms to execute but its taking 11 ms for me which is really slowing down my sampling rate. Any ideas what would cause this?

leaden walrus
#

how are you measuring the time?

gray holly
normal bough
#

Serial.println(millis()); directly before and after sensor.readData

gray holly
#

You can adjust the time using 6x6 buttons

normal bough
#

oh woops, lol you were talking to him

leaden walrus
#

ha! actually that q was for @normal bough

normal bough
#

oh lol

leaden walrus
#

that method may be somewhat inaccurate

#

there could be some overhead from the serial print getting in there

normal bough
#

well, I can believe that, but it wouldn't be off by a factor of 5 right?

leaden walrus
#

instead, save to variables and print after

normal bough
#

so the other way is that I'm printing millis() each time I read the data from the magnetometer. I can't print data any faster than once per 11 milliseconds which is a sampling rate ~90 and it should be 500

#

It's just that I'm confident its the sensor.readData function that is slowing the code down because I'm printing millis right before and after that and its the same 11 milliseconds that it takes for my whole loop

fierce plank
#

@normal bough It is connected using SPI or I2C? if it's i2c you could maybe up it to 400kHz mode

leaden walrus
#
start = millis();
for (int i=0; i<SAMPLES; i++) {
  readSensor();
}
end = millis():
avg_dt = (end - start) / SAMPLES
#

can also do something like that to average it out

normal bough
#

its i2c, and I'm not sure the board can do 400kHz, i tried to change it and nothing changed

#

with Wire.setClock(400000);

leaden walrus
#

you're sort of at the level that can be tricky to sleuth out with simple serial prints

normal bough
#

@leaden walrus I mean that its 11 ms between every two samples for minutes on end

elder hare
#

i can run this pattern on 1 strip just fine! but when running on 2 (each strip on separate pins) it flips out can anyone tell me why?

void StripSettings::Mitosis()
{
    const uint16_t start_pos = NUM_LEDS_PER_STRIP / 2;
    static uint16_t pos = start_pos;
    
    uint8_t cell_size = 1;
    fadeToBlackBy(leds.data(), NUM_LEDS_PER_STRIP, m_Spacing);
    for (uint8_t i = 0; i < cell_size; i++)
    {
        uint16_t pi = pos + (cell_size - 1) - i;
        uint16_t ni = (NUM_LEDS_PER_STRIP - 1) - pi;
        getColorMode(pi, m_Brightness);
        getColorMode(ni, m_Brightness);
    }
    pos++;
    if (pos + (cell_size - 1) >= NUM_LEDS_PER_STRIP){
      pos = start_pos;
    }
}

The pattern is shot to "Cylons" from the center and out 1 in each side so 1 left and 1 right

normal bough
#

I'm reading and printing continuously

fierce plank
#

printing could also slow it down significantly at lower baud rates

normal bough
#

im at 115200, and I could figure that out by just implement a whole bunch of extra serial prints that are meaningless and seeing if it makes it worse right?

#

but I'm pretty sure it won't I dont think it takes 10 ms to do a serial print of 30 bytes right?

fierce plank
#

I'm messing with some sensor reading atm, and sending "AccX: 0.010010, Y -0.026855, Z 0.881104" over uart at 115200 takes 3.7ms

#

Measured using one of those cheap logic analyzers, it's quite handy

normal bough
#

hmmm

#

Okay let me look into that and see if it helps and I'll report back after I do

fierce plank
#

For reference, each "block" in the I2C lines correspond to reading 12 bytes of data which takes 360 microseconds (400kHz I2C)

leaden walrus
#

being able to scope the lines really does help

fierce plank
#

for real, this is much nicer than having to blink LED's for debugging

acoustic nebula
#

good evening

#

Can someone help me with a bluefruit (Arduino) issue?

cedar mountain
#

The rule of thumb is just to ask your question, rather than waiting for a volunteer who has no idea if they'll know the answer ahead of time. 😁

acoustic nebula
#

ok

#

I've got a Peripheral service running on MacOS and I'm able to connect/use it fine from an ESP32 and Nano33. When I try to use the nRF52 bluefruit, it scans+finds it, matches the service UUID, but in the connect callback, the clientservice.discover() call always fails

#

(Arduino native code running on a nRF52840 feather and other bluefruit hardware)

flint smelt
#

I have '840's coming out of my ears, I could poke at it if you can provide some code for me to try?

acoustic nebula
#

You would need a Mac too. Haven't others had issues after the connect succeeds?

flint smelt
#

I have Macs as well. I think that @stuck coral is pretty familiar with nRF52840 from asking my own questions and a search of this channel

acoustic nebula
#

my code looks like any of the Central examples. There's nothing exceptional about it except that it fails the "discover()" call in the connect callback

#

I traced it into the bluefruit library and it's actually getting a "_adamsg.waitUntilComplete(BLE_DISCOVERY_TIMEOUT);" failure

acoustic nebula
#

thanks anyway, it has crossed the THX-1138 cost threshold and will be put aside 😦

eager willow
#

Is it safe to use HC-12 modules with any Arduino board ? Someone suggested me that HC-12 RX TX works on 3.3V logic and Arduino RX TX works on 5V logic, does it really matter ? Cause I have seen people using HC-12s on different Arduinos

maiden pilot
#

Hey all, I'm looking for a way to compensate for the drift of an MP6050 gyroscope running on an ESP32 compiled w/ arduino. Any tips?

flint smelt
#

Have you tried to rotate it to match the drift? 😛

#

Sorry, feeling kind of loopy tonight 😁

cedar mountain
#

Depends on what you mean by "compensate". Often people will take a zero reading in a known-stationary position on boot and then subtract that value from further readings. Slightly more sophisticated would be to calibrate it over temperature.

#

Do bear in mind that the MPU6050 is several generations back at this point, so if you need a higher-accuracy IMU, you might need to upgrade sensors. They'll all have some degree of gyro drift, though.

maiden pilot
#

Well, I'm trying to build an always-on device

#

So I'm looking for a way to compensate for the MPU's drift over time

#

it happens at a very consistent rate, so I'm hoping to just write some code that will gradually add/subtract from the total over time

cedar mountain
#

Yep, you can do that... it's commonly done as I mentioned above. Though eventually it'll still drift if you wait long enough. Ultimately the only answer is some sort of external orientation reference. People often use a magnetometer as a compass, for instance.

maiden pilot
#

hmmm. Any ideas for finding documentation for how to use another MEM as a reference?

cedar mountain
#

Using another similar MEMS sensor won't really help, as it will have its own drift. Gyroscopes only measure angular velocity, but they don't have any way to know absolute orientation per se.

maiden pilot
#

I see, are there any sensors that combine both, specifically to eliminate drift?

cedar mountain
#

Yes, a "9-axis" IMU typically integrates a magnetometer for that purpose. It's not foolproof, though, since magnetic fields indoors can be complex. The MPU9250 is the variant of the 6050 that does that.

maiden pilot
#

ahhh okay

#

will look into that

#

does mean effectively starting from scratch on the code though lol...

#

i had just gotten the MPU6050 working with the mahoney algorithm on an esp 32

cedar mountain
#

There's some decent compatibility between the two, since they're made by the same company.

vivid rock
#

@maiden pilot without a magnetometer, there is no way to avoid accumulating drift, but with proper data fusion algorithms, you can significantly reduce the drift rate

#

he uses madgwicks filter

elder hare
#

this is driving me nuts

Qt Side

socket.sendCommandStrip(QString("toggleUV"), QJsonValue(checked));

// Send Message (For Strips)
// =========================================================================================================== //
void Socket::sendCommandStrip(const QString &bName, const QJsonValue bValue)
{
    m_webSocket.sendTextMessage(QJsonDocument(QJsonObject{{bName, bValue}}).toJson(QJsonDocument::Compact));
}

ESP32 Side

    if (doc["toggleUV"])
    {
            ToggleUV = doc["toggleUV"].as<int>();
            Serial.printf("ToggleUV : %d \n", doc["toggleUV"].as<int>());
    }

so i send the bool over socket to my ESP32, in the Qt Consol i see

The Toggle button was :  true
The Toggle button was :  false

so i know that checked bool var is correct! but at the ESP32 side i only get this in the Serial Monitor

ToggleUV : 1 
ToggleUV : 1 

why..... 😦 i have a deadline in 4 hours!

lone ferry
#

@elder hare What happens if you Serial.println(doc["toggleUV"]); ?

elder hare
#

gonna try it

#

@lone ferry im not allowed to print that for some reason

#

more than one instance of overloaded function "HardwareSerial::println"

lone ferry
#

Don't know what that is but what I was getting at is that doc["toggleUV"] may not actually be an int.

#

By printing it out you might be able to see what it is instead.

candid topaz
#

this will be some kind of arduinojson class

lone ferry
#

Ah yes, so println won't have an overload for it unless you cast it. It's probably a string or a boolean.

elder hare
#

i figured i could cast it to int as bool is either 0 or 1 (it was just for testing anyway)

#

@lone ferry @candid topaz ty anyway! i dont have more time! i need to start updating and test all of my 8 neon installation befor the birthday party begins!

#

i just have to implement this later

#

i guess

hallow sand
#

Hi everyone !
I would like to track Instagram followers with an esp8266 to then build an iot device capable of reacting to the number of followers. I tried using the library "instagramStats" on the Arduino IDE but I'm far from being really good at Arduino 😅
If anyone is able to help me I would be very grateful 😊

hallow sand
#

Well I've been struggling a bit and I found out that this library doesn't work that well since the last Instagram update 😅

pine bramble
#

I've been looking at the johnny five js library(https://github.com/rwaldron/johnny-five) and it made me wonder if I could use it with express js to make a web server on a arduino that have a wifi chip

vivid rock
#

Sure - post your code here.

sterile scaffold
#

Hi, I'm having issues getting the SD card reader to work on the Adalogger feather shield. I'm running the CardInfo example sketch and it just keeps saying initialization failed. Here is what I've tried so far:

Set chipSelect = 10 in the code
Conductivity test from the rectangular pads next to SDCS on the wing down to pin 10 on the feather to ensure connection

#

Conductivity test every pin on the feather to the wing

#

Try 2 different SD cards (both formatted using the official SD card formatter linked on the page)

#

Try 2 different Feather/Wing combinations

#

I've also put a battery in for the RTC on the wing and confirmed that that works, but the SD card is just not working and I think I must be doing something wrong. I have an old WickedDevice board with an SD card reader and I have confirmed that it can read these cards, but my new Adaloggers cannot

#

The board is a M0 feather with LORA if that helps

cedar mountain
#

I'm not an expert with this board, but it's not immediately obvious that "10" is the right way to specify the pin, since it's pin 27 on the M0 chip pinout, and PA18 internally. Is it possible there is another more specific numbering scheme?

sterile scaffold
#

Thanks for the thought. I just tried using both of those pins for Chipselect and neither worked. I was using 10 because that's what the tutorial said to use, and when I conductivity test from the solder pads next to SDCS on the wing (which you're supposed to be able to use to change the pin) they connect to pin 10

obtuse spruce
#

According to the Feather M0 LoRa pinout it would be 10 for the pin number in the code.

sterile scaffold
#

I'm wondering if I may have issues with libraries

#

I think I've got them all installed correctly, but I'm not sure, and the tutorial doesn't go over that in depth

obtuse spruce
#

Quick things to check that you probably have right: 1) are you compiling for the right board (Feather M0 LoRa)? 2) Is the CS select trace on the featherwing still in tact?

sterile scaffold
#

the board I've selected is just Adafruit Feather M0

#

I don't see an option for a LoRa specific version. I have been able to get LoRa to work compiling to this target though

obtuse spruce
#

that'll work - the pin out for that is the same

sterile scaffold
#

I checked concutivity from the square solder pad next to SDCS to pin 10 on the feather, does that mean that the CS trace is still in tact?

obtuse spruce
#

and - er - another quick check - you did initialize the SD card on another computer, right?

sterile scaffold
#

yes, using the SD software linked on the Adafruit site even

obtuse spruce
#

There's a little copper between the two square pads - that is what should be in tact - visual inspection is probably enough

sterile scaffold
#

and I can read this card in another Arduino board (from Wicked Device)

obtuse spruce
#

good, okay - then all "obvious things to check" sound good

sterile scaffold
#

yes that copper between the pads is there visually and I just confirmed conductivity as well

#

Also note I've tried this code with 3 pairs of feather/adalogger and none work. This makes me think it's likely on the software side, which is why I'm wondering about libraries (which is something I don't have a lot of experience with)

cedar mountain
#

Stupid question: all the headers are soldered, right? (Sometimes we've seen people try to get away with just sticking the pins in and calling it good.)

sterile scaffold
#

yes headers are all soldered and I've painstakingly tested conductivity from wing to feather for each one, and tested that there is no conductivity between any adjacent pairs of pins

obtuse spruce
#

yeah - this sounds like software - first thing - use the Library Manager in the Arduino IDE to ensure that everything is updated.... and ditto with the Board Manager

sterile scaffold
#

so in boards manager I have 1.8.9 of Arduino SAMD Boards (32-bits ARM Cortex-M0+) installed. I think thats what I need for this board right?

#

In libraries I have version 1.2.4 of SD installed

#

I think that's all this should require, though the sketch also includes SPI.h

#

does that come along with the SAMD Boards stuff, or is it in some separate library?

obtuse spruce
#

Oh - uhm, I'd think that you'd have the Adafruit SAMD boards installed

sterile scaffold
#

Oh looking down I see Adafruit SAMD Boards version 1.6.4 as well

#

I'm now selecting M0 in there instead of in the 32-bits one and seeing if that works

obtuse spruce
#

there is drop down that lets you select "Updatable" at the top - which is easier to see if you need updating... but 1.6.4 is latest

sterile scaffold
#

Oops that was my mistake, the option I selected was "Arduino M0" under Arduino SAMD Boards (32-bits ARM Cortex-M0+) but that's not "Arduino Feather M0" so selecting it breaks stuff. Going back to "Arduino Feather M0" under "Arduino SAMD Boards (32-bits ARM Cortex-M0+ and Cortex M4) Boards" does allow me to connect to the board and interact, but the SD card still doesn't work

#

I wonder if there's a possibility of conflicts between libraries/boards I have installed? That seems like a long shot, but what else could be causing this

obtuse spruce
#

Hoping.... hoping... that you mean "Adafruit Feather M0" under "Adafruit SAMD Boards"

sterile scaffold
#

no, I wrote the full names out

obtuse spruce
#

Most popular libraries - and certainly all that Adafruit tutorials tell you to use - are designed to work with multiple boards from different sources.

#

Then no - you are still picking the wrong board

sterile scaffold
#

even though I have "Adafruit SAMD Boards" installed in my Boards Manager, it doesn't show up as a sub menu under Tools->Board

obtuse spruce
#

the first category under Boards should be Adafruit SAMD

#

Then under that you want Feather M0

#

That seems odd that you don't have it

sterile scaffold
#

What shows up for me is "Arduino SAMD Boards (32-bits ARM Cortex-M0+ and Cortex M4) Boards" and under that "Adafruit Feather M0"

#

I'm going to remove "Arduino SAMD Boards (32-bits ARM Cortex-M0+)"

obtuse spruce
#

(I'm actually at 1.6.2 and am updating at this moment to see if they moved things around in the menus...)

sterile scaffold
#

cool, I'm going to install 1.6.2 of Adafruit SAMD Boards to see if may that works

#

BTW thanks for all the helpo

sterile scaffold
#

went down to 1.6.2 and the name in the boards menu still shows up the way I typed it. Uploaded code at this level and still no success. I'm going to completely uninstall and reinstall and 1.6.2 from scratch and see if that does anything

#

Interesting, even after totally uninstalling it and reinstalling 1.6.2 my Boards sub menu still says "Arduino SAMD Boards (32-bits ARM Cortex-M0+ and Cortex M4) Boards"

#

selecting Adafruit Feather M0 in that sub menu does allow me to find the board and interact with it though. But SD card reading still fails

obtuse spruce
#

You might try installing the Adafruit SPIFlash library - and trying the flashinfo exmample in that one

iron bobcat
#

hi, i needed some help to do an easy program with arduino, I'm having problems with the exporting of data to an excel

#

It's quite a simple program just implementing a PID regulator with a power resistor and a sensing resistor, I wanted to export temperature vs time, but I'm not able to find any way to xport this correctly

obtuse spruce
#

@iron bobcat -- A simple approach would be to have the arduino output the data to the serial line in CSV format ... then that will be trivially importable into any spreadsheet

iron bobcat
#

yes but i need to do that automatically ://

obtuse spruce
#

what do you mean - like - somehow adding data into an Excel spreadsheet as the Arduino is running?

#

If so - that is a problem of Excel programming... which I'm guessing people here won't know much about.

iron bobcat
#

yeah i just meant that :// thanks a lot anyway for your help, i was expecting someone to already have solved this in some way

obtuse spruce
#

well - is the final goal to have it in Excel?

iron bobcat
#

the final goal is to implement an industrial sensor, capture is data, and monitor it in real time, and i'm afraid my useless teacher won't think serial printing is allright, he preffers us to use a data aquisition card which we only have available 2h once a week or when he finds correct T.T

#

That's why i'm trynna do it with arduino, so that i can do some work at home, but i'm afraid i will have to step over this part finally :/

obtuse spruce
#

and he wants you to monitor it in real time with an Excel spreadsheet?!??

unborn frost
#

Hey, looking for some help with my nodemcu board. I am trying to make a web request but its not working. all its doing is printing '-1' and then a newline. here is the code im using:

obtuse spruce
#

you are using an obsolete begin() API

#

Your call should look like this:

http.begin(WiFi, Link);
#

er

#

wait

#

So, somethin glike

#
    // at top of Loop():
    WiFiClient client;
    HTTPClient http;
    // then later in loop():
    http.begin(client, Link);
unborn frost
#

great thanks so much, will try that now. was using example sketch from the esp8266 library so idk why its so outdated

obtuse spruce
#

I don't know why they leave that old API in the .h file - since it always generates an error when running. Better to catch that at compile time by just not having it!

#

oh - nevermind - it should generate an error at compile time... perhaps you missed it

thick stag
#

(Sorry to jump in the middle of this convo!) I've got an Itsy Bitsy M0 Express that is currently setup with Circuit Python and I'm trying to upload Arduino code but I keep getting "Port Busy". Google is failing me. Any thoughts?

#

(two editors open at once was the answer ^)

obtuse spruce
#

you need to "double tap" the reset button fairly fast... to get out of CircuitPython and into the bootloader. You should see a drive on your desktop that doesn't have .py files on it... then you know you're in the bootloader

#

Oh - never mind

frank grotto
#

When trying to use the TinyUSB library on a Feather NRF52832 I get the following error:

error TinyUSB is not selected, please select it in Tools>Menu>USB Stack

Under Tools there is no USB Stack option. Am I missing something? Thanks!

obtuse spruce
#

Have you selected the Adafruit version of the board from the board menu?

frank grotto
obtuse spruce
#

so yes!

#

Normally, the Adafruit cores add a USB menu so that you can pick from the standard Arduino USB support or TinyUSB support.

#

Perhaps TinyUSB isn't supported on that board?

frank grotto
#

I think the NRF52* boards have TinyUSB by default

obtuse spruce
#

welllllllll then something is amiss as there is a -D define that the core should be injecting to signal that it expects to use TinyUSB

#

hrm..... no idea then....

frank grotto
#

Hmm ok, thanks :)

lusty mountain
#

I'm looking for some help with code i'm trying to write

#

There are 4 buttons, with Button1 and Button2 controlling their own respected loops, operating an LED and a relay. At the moment, all the buttons do is momentarily trigger their respected loops. I'm hoping I can get some help with making it so the buttons can trigger their respected loops, have it repeat for one minute (regardless of if the button is depressed or not), and have it automatically end, unless a different loop overrides it in the middle of it's cycle. Button3 simply momentarily turns on the LED and Relay, and Button4 is supposed take priority and cancel any loop that might be playing. Is this able to be done with the delay() command, or is it more complicated? I looked up the loop() command, and I wasn't quite able to wrap my head around it. If someone could help me out, that would be awesome. Thanks.

#
int RELAY2=3;
int RELAY3=4;
int RELAY4=5;

int LEDPin1=6;
int LEDPin2=7;
int LEDPin3=8;
int LEDPin4=9;

int button1=10;
int buttonRead1;
int button2=11;
int buttonRead2;
int button3=12;
int buttonRead3;
int button4=13;
int buttonRead4;
int dt=10;
void setup() {

Serial.begin(9600);
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin2, OUTPUT);
pinMode(RELAY1, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
}

void loop() {
buttonRead1=digitalRead(button1);
buttonRead2=digitalRead(button2);
buttonRead3=digitalRead(button3);
buttonRead4=digitalRead(button4);
Serial.println(buttonRead1);
Serial.println(buttonRead2);
Serial.println(buttonRead3);
Serial.println(buttonRead4);
delay(dt);
if(buttonRead4==1){
   digitalWrite(LEDPin1,LOW);
   digitalWrite(RELAY1, HIGH);
}
if(buttonRead3==1){
   digitalWrite(LEDPin1,HIGH);
   digitalWrite(RELAY1, LOW);
}
if(buttonRead3==0){
   digitalWrite(LEDPin1,LOW);
   digitalWrite(RELAY1, HIGH);
}
if(buttonRead2==1){
   digitalWrite(LEDPin1,HIGH);
   digitalWrite(RELAY1, LOW);
   delay(200);
   digitalWrite(LEDPin1,LOW);
   digitalWrite(RELAY1, HIGH);
   delay(200);
}
if(buttonRead1==1){
   digitalWrite(LEDPin1,HIGH);
   digitalWrite(RELAY1, LOW);
   delay(500);
   digitalWrite(LEDPin1,LOW);
   digitalWrite(RELAY1, HIGH);
   delay(500);
}

}```
obtuse spruce
#

This is more complex than you might think, and you can't use delay to achieve what you want... because when delay() runs... nothing else happens -- so the code isn't checking buttons and the like.

#

The way to approach this is to think about what "states" can the system be in:

  1. It is doing nothing - the LED is off, the relay is off
  2. It is playing loop A - fiddling with the LED and the relay... and it has a time in the future, after which it will return to state 1
#
  1. it is playing loop B - ... similar to previous state
#

On top of this - there is "an override" - and extra bit of state (controlled by button 3) -- where the outputs are forced on.

#

Have I described all the states the system can be in?

#

Also - it looks like you expect the two loops to be the same - simply blink on/off the LED & relay --- but at different rates.

#

Is that the case?

lusty mountain
#

Exactly

obtuse spruce
#

Okay - let's just restate that in code:

#
if (override) {
  setOutputsOn();
  return;
}
if (looping) {
  if (now >= timeToEndLoop) {
    setOutputsOff();
    looping = false;
    return;
  }
  if (now >= timeToFlip) {
    loopState = !loopState;
    timeToFlip = now + loopFlipInterval;
  }
  if (loopState)  setOutputsOn();
  else            setOutputsOff();
  return;
}
// idle!
setOutputsOff();
#

I've been called to dinner... I'll be back in about an hour...
You should be able to make that code actually run as written! Think about what extra parts you need to write to make it run.

lusty mountain
#

Thanks for the help!

gray holly
#

I'm using a set of led strips like this, but when uploading the sketch, I can't seem to control them

#

Power starts at the end and ends at the board, so why can't I control anything

#

Only one led lights up purple, nothing else changes

cedar mountain
#

Can you link to your code? I don't see anything immediately wrong in the wiring.

gray holly
#

Is it a hardware problem?

#

I can see messages being sent from serial monitor

cedar mountain
#

Okay, there's a lot going on in this code. Have you tried something more like a LED test program?

gray holly
#

Hmm

#

Where can I find one?

#

I'll just look online

cedar mountain
#

Adafruit will likely have some NeoPixel demo code.

gray holly
#

They're not neopixels, but they work with fastle

#

d

gray holly
#

I think there's some sort of hardware issue, but I can get voltage from every strip

cedar mountain
#

Is your power supply beefy enough for all of the LEDs?

gray holly
#

Yes

#

full 5 volts tested with multimeter

cedar mountain
#

No, I mean how much current it can supply. Possibly that 5V won't be stable once the LEDs actually turn on.

gray holly
#

6 amps so 30 watts

cedar mountain
#

Cool, that should be good for around 100 LEDs at full brightness, assuming they're relatively normal RGBs.

gray holly
#

I have 67

#

They are WS2812B model

vivid rock
#

these are neopixels

vivid rock
#

neopixel is just the name Adafruit gave to WS2812b leds

gray holly
#

ohh ok

#

I thought neopixel was adafruit's brand

#

What is the problem with these lights then?

vivid rock
#

no, they (or someone affiliated with them) invented the name - they didn't invent the actual chips

pulsar junco
#

it's a maytag/whirlpool situation. Same washer, different name

vivid rock
#

can you check that you are connecting data line to the beginning of the strip, not the end?

vivid rock
#

neopixel strips are directed

gray holly
#

So I should try reversing the strip?

#

The very end and the very beginning

vivid rock
#

there shoudl be arrows on the actual strip

cedar mountain
#

The schematic you posted shows DIN versus DO.

gray holly
#

That would be fine since it's symmetrical

vivid rock
#

showing direction in which the data travels

gray holly
#

Ok I see arrows

#

so they should point from board to psu?

#

or other way around

vivid rock
#

power (5v and gnd) can be connected from either end, it deosn't matter

gray holly
#

what about data?

vivid rock
#

the data line shoudl be connected to the beginning of the strip

gray holly
#

My arrows start from the psu and point to board

#

So I assume that's wrong

vivid rock
#

it is wrong

gray holly
#

Alright I'll try switching them and I'll get back to you

#

Thanks!

cedar mountain
#

Good catch, @vivid rock !

gray holly
#

Does the arduino sketch save if you power it off?

#

I've been a pi guy my whole life, this is my first experience with them

vivid rock
#

it does

#

@cedar mountain thanks... the only way to know what silly mistakes people make is to make them all yourself 🙂

gray holly
#

So basically it's only able to run one program at a time, and runs it as soon as it's powered on

vivid rock
#

yes

gray holly
#

cool cool

#

I'll go swap them now

#

I'm new to soldering too, I just soldered 3 strips to each other, and now I have to resolder some stuff again

#

Cheers

vivid rock
#

I feel your pain 🙂

gray holly
#

It's so hard sometimes

#

Like the metal will turn liquid when you don't want it to and vice versa

#

Or jump to another pin

vivid rock
#

both adafruti and sparkfun have nice basic soldering tutorilas

gray holly
#

Will I have damaged anything by doing it backwards?

vivid rock
#

no

#

and of course there are hundreds of tutorials on youtube

gray holly
#

youtube is magical

lusty mountain
#

I'm still having trouble integrating @obtuse spruces code with mine

#

this stuff is confusing

obtuse spruce
#

I'll be back in about 15 min or so

lusty mountain
#

Thanks

gray holly
#

Back

#

Let's go moment of truth

#

YOO

#

WE GOT IT WORKING

#

bruh nvm 😔

#

Only the strip connected right next to the arduino works

#

the others don't do anything

#

I think there's a problem with the data somewhere

pulsar junco
#

are all your strips the same direction?

obtuse spruce
#

okay - @lusty mountain - I'm back

gray holly
#

and yes they are

pulsar junco
#

Was just checking, I've made that mistake myself

gray holly
#

I'm thinking it's just bad soldering on one of the data things

#

I'll check back tomororw

lusty mountain
#

does the code you sent me simply replace the code which cycles the relay and LED?

   digitalWrite(LEDPin1,HIGH);
   digitalWrite(RELAY1, LOW);
   delay(200);
   digitalWrite(LEDPin1,LOW);
   digitalWrite(RELAY1, HIGH);
   delay(200);
}```
obtuse spruce
#

No. It replaces much much more...

#

So - some quick questions - how solid on you on the concept of a function - and of what loop() does in an Arduino program?

lusty mountain
#

I havent learned anything about loop() yet

#

I did some research and there was some talk about millis(), but i'm not quite in depth enough to understand it

obtuse spruce
#

Got cha' --- okay - so loop() is a function that is called by the system after setup() is complete. The system calls loop() again and again and again... forever.

#

You get to write loop() and say what happens.

#

Otherwise there is nothing special about loop() -- it's just a function.

#

Since it is called forever --- a good way to think of loop() is this: "What is the current state of the system -- my variables, and my inputs --- and what changes do I need to make in response - to the variables, and the outputs."

#

And by inputs I mean those things you read with digitalRead. And by outputs, those you write with digitalWrite

#

(well, and the analog versions as well, if you were using those)

lusty mountain
#

so loop basically reads the inputs, and controls the outputs depending on what it reads?

obtuse spruce
#

right -- and it may set some variables.

pine bramble
#

Sorry @obtuse spruce and those who have helped me yesterday for my sudden absence. Something came up sadly, so I had to take my leave. If possible, could anyone help me again? I have added a few touches, but I'm generally confused on the code haha . . . (Pastebin : https://pastebin.com/dsLtdLbp) (Picture of circuit :

#

As for what I want the circuit to do, I want the potentiometer to dictate the value / angle of the servor motor, I want the phototransistor to "alarm" the piezo, and I want the button as a, sort of, reset button.

obtuse spruce
#

Okay - let's start with something very very simple, and mutate it into what you need, @lusty mountain
Start with this:

const int LEDPin = 6;

void setup() {
  pinMode(LEDPin, OUTPUT);
}

bool ledState = false;
unsigned long nextFlip = 0;

const unsigned long flipPeriod = 800; // ms

void loop() {
  unsigned long now = millis();
  
  if (now >= nextFlip) {
    ledState = !ledState;
    digitalWrite(LEDPin, ledState ? HIGH : LOW);
    nextFlip = now + flipPeriod;
  }
}

This is a "blink the LED" program written in this "state machine" style. There is a simpler blink program...one that uses delay() -- but it is hard to extend that to do anything else.

#

Read this code (or run it even!)

#

Let's make sure you understand every single line of it.

#

If you do -- extending it to what you want to do today (and what you want to do tomorrow!) will be much easier that attacking the whole enchilada.

lusty mountain
#

It's running right now

obtuse spruce
#

(Also - other folks - feel free to ask questions, too -- @lusty mountain 's goal - and the structure of the code that will support it cleanly - is a very very common situation I see here. If you can get over this first hump... you'll be in good standing for doing more.)

#

And is that LED blinking nicely?

lusty mountain
#

Yes

obtuse spruce
#

Cool -- now look at it and see if you understand why

#

note - every single word there is important. as is the formatting.

gray holly
#

The strips are 32-3-32

#

But only the one closest to the arduino can be controlled

pulsar junco
#

@obtuse spruce I'm curious: I use a slightly different construct to do timing (sorry for the python in this channel). Is your method superior?
my ex:


init = time.monotonic()
interval = 0.1
while True:
  now = time.monotonic()
  if (now - init >= interval):
    init = now
    #do stuff
#

I ask because I see your method all the time in arduino stuff

#

oh gosh I wrote it backwards, it is too late

obtuse spruce
#

The two are isomorphic - they implement the same thing..... but I write mine my way for reasons of clarity:

  1. you don't need to apply any thought to the if clause "if now is at or after when X needs to happen.... " The otherway makes you stop and think it through -- when really that isn't what you want to be focusing on when reading that line of code.
  2. the interval for "when to do the next thing" can easily be computed while doing the current thing... like if the next time to move the servo were in part based on a reading. Your style, you'd have to put that logic in or just before the if -- or have a variable for the interval... which feels wrong to me
  3. if you have multiple things going on - with multiple "time to do the next thing variables" -- it is much easier to reason about my way
pulsar junco
#

interesting, I have some old code I need to implement a state machine for that does what's in your point 3. IDK why but this makes my eyes cross less

obtuse spruce
#

Your way has one advantage - it works when now overflows its type and rolls over. Mine does not.... But really - one should never rely on such logic - as rolling over of counters is dangerous business

#

Really #1 is probably the biggest reason - and the flexibility of #2 is pretty grand

#

don't ever underestimate the power of making the code clear and read directly --- your next-week's-self will thank you

pulsar junco
#

is nextFlip rolling over a concern as well?

lusty mountain
#

still trying to figure things out

#

what role does "const unsigned long" play?

pulsar junco
#

I'm sorry for interrupting

lusty mountain
#

np

obtuse spruce
#

well - that is my point - if you are writing something that is going to run long enough that millis() might roll over -- you need to be thinking about long time scales in general.

#

@lusty mountain - const means "I promise to never ever change this value... yell at me if I try"

pulsar junco
obtuse spruce
#

unsigned long is a type - it is a declaration of what kind of integers can be represented. In Arduino, milliseconds are represented by unsigned 32 bit numbers, or unsigned long

#

So unsigned long nextFlip = 0; means nextFlip is a variable that can change, of the size to hold milliseconds, and with an initial value of 0.

#

Whereas, const unsigned long flipPeriod = 800; means flipPeriod is a variable that can never change, of the size to hold milliseconds, and with a value of 800.

#

Notice that I made LEDPin and flipPeriod values which never change.... because I want the compiler to tell me if I make a mistake and accidentially write to those variables. If you take the const out - everything will still run (after all, the code doesn't change those variables) --- but you have no protection.

#

All your names for pins should be const... I can't tell you how many times I see code where the compiler would have caught the bug had people used const.

#

@pulsar junco - millis() gets you 49 days of uptime before you need to worry.

pulsar junco
gray holly
#

The strips are 32-3-32, but only the one closest to the nano board will work. Any idea why?

#

The arrows are all in the right direction

obtuse spruce
#

@pine bramble - let's go slowly on this...

    LED1Here = digitalRead(LED1); // Reading the digital output of LED1

Why are you trying to read an LED?

#

LED1 is a pin that you've set to OUTPUT in setup(), presumably because you want to turn it on and off, which you do by calling digitalWrite().

#

Reading from it won't get you anything.

#

also - read what I said about const above - every delcaration on lines 4 to 12 in your code should have const in front of it.

lusty mountain
#

okay, so how do I trigger the loop with a button?

pine bramble
#

Oh, so basically outputs don't need digitalRead? It's just a uneffective / extra line of code?

obtuse spruce
#

@lusty mountain - you'll need some more state - a variable bool blinking = false;

#

here's the next step:

const int LEDPin = 6;
const int button1Pin = 10;
const int button2Pin = 11;

void setup() {
  pinMode(LEDPin, OUTPUT);
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
}

bool blinking = false;
bool ledState = false;
unsigned long nextFlip = 0;

const unsigned long flipPeriod = 800; // ms

void loop() {
  unsigned long now = millis();
  
  if (digitalRead(button1Pin) == HIGH) {
    blinking = true;
    ledState = false;
    nextFlip = now;
  }
  if (digitalRead(button2Pin) == HIGH) {
    blinking = false;
    digitalWrite(LEDPin, LOW);
  }
  
  if (blinking) {
    if (now >= nextFlip) {
      ledState = !ledState;
      digitalWrite(LEDPin, ledState ? HIGH : LOW);
      nextFlip = now + flipPeriod;
    }
  }
}
#

This uses buttons 1 and 2 to start and stop the blinking..... but once you understand this code.... extending it to do what you originally specified should be clear.

lusty mountain
#

I think I got it working

#
const int button1Pin = 10;
const int button2Pin = 11;
const int button3Pin = 12;

void setup() {
  pinMode(LEDPin, OUTPUT);
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
}

bool blinking1 = false;
bool blinking2 = false;
bool ledState = false;
unsigned long nextFlip = 0;

const unsigned long flipPeriod1 = 800; // ms
const unsigned long flipPeriod2 = 300; // ms

void loop() {
  unsigned long now = millis();
  
  if (digitalRead(button1Pin) == HIGH) {
    blinking1 = true;
    blinking2 = false;
    ledState = false;
    nextFlip = now;
  }
  if (digitalRead(button2Pin) == HIGH) {
    blinking1 = false;
    blinking2 = true;
    nextFlip = now;
  }
  if (digitalRead(button3Pin) == HIGH) {
    blinking1 = false;
    blinking2 = false;
    digitalWrite(LEDPin, LOW);
  }
  
  if (blinking1) {
    if (now >= nextFlip) {
      ledState = !ledState;
      digitalWrite(LEDPin, ledState ? HIGH : LOW);
      nextFlip = now + flipPeriod1;
    }
  }
  if (blinking2) {
    if (now >= nextFlip) {
      ledState = !ledState;
      digitalWrite(LEDPin, ledState ? HIGH : LOW);
      nextFlip = now + flipPeriod2;
    }
  }
}```
#

I really appreciate the help

obtuse spruce
#

Cool

#

BUT

#

Notice that you have a bit pile of duplicated code....

#

What's the difference between the if (blinking1) block and the if (blinking2) block?

#

When you see duplicated code - with only a tiny difference - you should immediately think about how to not have duplicated code.

#

Two ways: 1) use a variable, 2) create a function

#

Let me point you:

const unsigned long flipPeriodSlow = 800; // ms
const unsigned long flipPeriodFast = 300; // ms

bool blinking = false;
bool ledState = false;
unsigned long nextFlip = 0;
unsigned long activeFlipPeriod = flipPeriodSlow;
#

try making this your state

#

I think you'll find the body of loop() gets simpler by about 11 lines!

lusty mountain
#

do I need to have a different activeFlipPeriod for every state?

#

so if there's unsigned long activeFlipPeriod = flipPeriodSlow;
I would also need unsigned long activeFlipPeriod = flipPeriodFast;
right?

obtuse spruce
#

no on

#

no

#

So - first, you can have two variables named the same.

#

Second - it isn't const! so you can change it--- in otherwords, the "blinking" code can just use whatever it is currently set to..... then... when would change to fast? when to slow?

lusty mountain
#

ohhh, I see what you mean

obtuse spruce
#

🙂

lusty mountain
#

unsigned long activeFlipPeriod = flipPeriodSlow;
changes to
unsigned long activeFlipPeriod = flipPeriodFast;
when the button2 says so?

obtuse spruce
#

almost.... let's look at three statements:

unsigned long activeFlipPeriod = flipPeriodSlow;
...
activeFlipPeriod = flipPeriodSlow;
...
activeFlipPeriod = flipPeriodFast;
#

The first line there is a declaration & definition - it causes the compiler to create the thing named activeFlipPeriod , and initialize it (before your program code runs) to the value flipPeriodSlow.

#

You can only have one definition of any thing in C++. Defining it again is a no no!

#

The second and third lines are assignment statements - the are code that is executed when the program flow of control reaches them (say, in a loop or inside an if...) - and when they are executed, the set the value of the variable activeFlipPeriod to the value given on the right of the =. The variable will continue to hold that value until it assigned to again.

#

Notice that inside the if we didn't say bool blinking = true; just blinking = true; - we weren't trying to define a new blinking variable - just use the one defined above and set its value.

lusty mountain
#

okay, that makes sense

#

I tried using flipPeriodSlow
it said it's not declared

obtuse spruce
#

well, did you declare it?

const unsigned long flipPeriodSlow = 800; // ms
const unsigned long flipPeriodFast = 300; // ms
#

these are just constants - so that we have nice names for otherwise arbitrary numbers;

lusty mountain
#

Yes

obtuse spruce
#

I'm hoping that you have something like this:

  if (digitalRead(button3Pin) == HIGH) {
    ...
    activeFlipPeriod = flipPeriodSlow;
    ...  
  }
lusty mountain
#

ohhhhh

obtuse spruce
#

in otherwords: "When the button is pressed... ... and set the active flip period to the slow period ...."

#

along with the other stuff in there

lusty mountain
#

so replace
blinking=true;

#

with
activeFlipPeriod = flipPeriodSlow;?

obtuse spruce
#

well... think about the rest of the code... do you still need blinking?

#

(the ... in my code snippit above was indication that I wasn't copying all the code)

lusty mountain
#

oh okay

obtuse spruce
#

And - do you need blinking1 and blinking2 any more?

#

And - will you need two if blocks at the end to do flipping? or one?

lusty mountain
#

I don't think so

#

If I learned everything correctly, "blinking" only need to be defined once?

obtuse spruce
#

Let's talk about definition and assignment

#
bool sawACat = false;

void loop() {
  if (readCatSensor()) {
    sawACat = true;
  }
  if (digitalRead(catResetPin) == HIGH) {
    sawACat = false;
  }
}
#

There is one definition of sawACat -- at the top.
There are two assignments to sawACat -- inside loop()

#

The value will change as the program progresses (and the sensors and the buttons get triggered)

#

You need a state variable blinking because sometimes your code is blinking and sometimes it is not

#

You need to define it, just once. And it is good form to give it an initial value (which admittedly looks like an assignment...)

#

But over the course of the program execution - different events (buttons) will cause that value to change by assigning to it.

lusty mountain
#

that's what was confusing me

#

I thought it was an assignment

obtuse spruce
#

You already had this coded with blinking1 and blinking2 --- look at your code - one definition - and two assignments.

#

The key in C++ is the presence of the type in front of the name. That is what makes it a declaration.

#
int numberOfCatSeen = 0;   // declares, defines, and initializes
int funnyThing;            // declares, and defines... but initialization is "default"
void noteACat() {           // declares & defines a function
  numberOfCatsSeen = numberOfCats + 1;   // uses & assigns existing variable
}
void resetCat() {
  numberOfCatsSeen = 0;     // assigns
}
void noteTwoCats() {
  noteACat();               // calls a function
  noteACat();               // calls it again
}
#

notice that the declarations all have a type (int or void)

#

the uses, assignments, and calls don't

lusty mountain
#

okay

#

does that mean I need
bool blinking = false;?
if I understand everything right, instead of needing to define "blinking" multiple times (blinking1, blinking2, etc), all I need is
unsigned long activeFlipPeriod = flipPeriodSlow;

#

is this correct?

#

err, not define, but declare

obtuse spruce
#

you also need a single variable, blinking because sometimes you are and sometimes you are not

#

so one declaration

#

bool blinking = false; -- declare it, and start it off not

#

but you'll set it to true and false as needed in response to the buttons

#

you need a variable activeFlipPeriod because sometimes the period is fast, and sometimes it is slow

#

again, one declaration... but set to various values as needed in response to the buttons

#

Think of it this way: Your system is defined as: "I am either blinking, or I'm not. And if I'm blinking, then I'm blinking at a current active blink rate. Also, if I'm blinking, I'm either currently on or off, and I know the next time that I need to flip."

#

So that is four things that define the state of your system:
am I blinking

#

the current active blink rate

#

the current state of the LED

#

the next time I need to flip the LED

#

and those four things will translate directly into four declarations

#

But - the value of those things will change as the program responds to buttons - these are the assignments

lusty mountain
#

okay, I think I changed all of the things you mentioned

#

I'm running the code now, and both of the buttons assign the same flip period, flipPeriodSlow

#

I think I have everything declared above

const unsigned long flipPeriodFast = 300; // ms```
#

I also have unsigned long activeFlipPeriod = flipPeriodSlow;

obtuse spruce
#

that is just the initial value of the active flip period

#

if I press button1 what do you want the active flip period to be?

#

if I press button2 what do you want the active flip period to be?

lusty mountain
#

I think I have that assigned too

    blinking = true;
    activeFlipPeriod = flipPeriodSlow;
    ledState = false;
    nextFlip = now;
  }
  if (digitalRead(button2Pin) == HIGH) {
    blinking = true;
    activeFlipPeriod = flipPeriodFast;
    ledState = false;
    nextFlip = now;
  }```
#

I'm pretty sure i'm missing something

obtuse spruce
#

that looks right

#

good

#

now - at the bottom?

#

the if block that actually does the blinking - what does that look like?

#

or do you have two?

lusty mountain
#

I have one

obtuse spruce
#

good

lusty mountain
#

Is that the problem?

#
    if (now >= nextFlip) {
      ledState = !ledState;
      digitalWrite(LEDPin, ledState ? HIGH : LOW);
      nextFlip = now + flipPeriodSlow;
    }
  }
}```
obtuse spruce
#

well - when is the next flip?

#

read line 5 out loud

lusty mountain
#

🤦

obtuse spruce
#

🥳

lusty mountain
#

Do I need two of those, one for flipPeriodSlow;, and one for flipPeriodFast;?

obtuse spruce
#

Do you know about "rubber duck debugging"? It is the practice of reading your code to the rubber duck perched on your monitor.... It really works!

#

No no - this whole exercise has been to get you to have only one block of code that does the blinking

lusty mountain
#

Ohh okay

#

and I imagine it does work. The problem was right in front of my face

obtuse spruce
#

so - "If I'm blinking.... and it is time for the next flip.... I'm going to flip the led state, and write out the LED pin, and set the next time to flip to now + ________" Go look at the four state variables and fill in the blank

lusty mountain
#

okay that makes sense

#

so if I want to control two different states, i'm going to need this, but twice? One for one flip period, and one for the other?

    if (now >= nextFlip) {
      ledState = !ledState;
      digitalWrite(LEDPin, ledState ? HIGH : LOW);
      nextFlip = now + flipPeriodSlow;
    }
  }```
obtuse spruce
#

no

#

once

#

once

#

once

#

what I tell you three times is true

lusty mountain
#

okay okay

obtuse spruce
#

so - think about this: You are blinking, it is time to flip... you flip the led, you write the led, and the next time you want to flip is __________ it is one of the four state variables... which one?

lusty mountain
#

activeFlipPeriod?

obtuse spruce
#

tada

lusty mountain
#

there we go

#

that makes sense

obtuse spruce
#

The lesson here is - but creating a state variable to hold the thing that changes --- the code that uses that variable doesn't have to be concerned with the changes... it just uses it - which means it can be written once.

lusty mountain
#

sorry for being a bit slow

obtuse spruce
#

"I'm the blinking code - I'm the if block at the end of the loop - I don't give a fig what period is the next flip time... some other code worried about that.... I just do this same thing every time... next flip is now + active flip time.... dum dumdum"

#

no problem - forgive me for dragging you through it to see it rather than just code it for you

lusty mountain
#

oh no problem, it's better to learn it, especially if I want to change anything later on

obtuse spruce
#

exactly

#

okay - I'm off to bed

lusty mountain
#

arduino is a bit more difficult than I anticipated

#

Alright, thanks for teaching me. night

obtuse spruce
#

night

heavy furnace
#

Hey all, I'm trying to upload to my new Trinket 3V with PlatformIO, but I'm getting this error:
#avrdude: 6 retries during SPI command (repeated a lot of times). Verification fails and my code isn't running.

#

It's plugged into my laptop's only USB2 port, but I've also tried the USB3 ports just in case

#

I've updated the avrdude.conf as specified on the website

heavy furnace
#

Hmm it seems to work fine with the Arduino IDE

#

but not with PlatformIO

gray holly
#

I am trying to control these led strips like this, the strips are 32, 3, and 32.

#

For some reason, I can only control the strip closest to the board.

obtuse spruce
#

@gray holly when you say 32-3-32 do you mean that you have three physical steps of those lengths soldered together into one long 67 LED strip?

gilded gazelle
obtuse spruce
#

Those are for low level gpio register twiddling... If you are using Circuit Python, why not just use the LED libraries?

gilded gazelle
#

I am using arduino

#

the project is in arduino, see link

obtuse spruce
#

Oh sorry misread qtpy ....

#

... clearly I shouldn't post before ☕

gilded gazelle
#

lol

#

I need to find out how to adjust those defines for samd21

#

I have yet to find the reference to tell me what they mean as they are

obtuse spruce
#

just looked at the source code

#

those are the direction and port registers, and the bit mask, for the particular pin the LEDs are on.

#

The code does things like this:

  LED_DDR  |=  LED_PIN; // Enable output for LED
  LED_PORT &= ~LED_PIN; // LED off

which could be replaced by

  pinMode(LEDpin, OUTPUT);
  digitalWrite(LEDpin, LOW);
#

and where you define the pin in a more conventional manner:

const int LEDpin = 6;  // or what ever pin you have them connected to
#

actually - since the LEDs around the monitor are accessed via SPI....
I think this LED manipulation is just to blink the on board LED to let you know what state the code is in.

#

The CircuitPlayground version, for example, doesn't bother.

#

I think you can just comment out everything dealing with those #defines and be good to go.

gilded gazelle
#

ok I will try that

#

thank you

#

using the plain ledstream code

obtuse spruce
#

yeah - that code is the older of the examples and seems to be written for a much older version of the Arduino environment.

gilded gazelle
#

commenting out cause error on compile

obtuse spruce
#

you have to comment out the lines that reference those values as well

gilded gazelle
#

that is a lot of lines

#

also comment out contents of while's that check the value??

#

wont be much code left

obtuse spruce
#

what?

gilded gazelle
#

I got everything commented, let you know

obtuse spruce
#

there are just the three defines and four more lines

#

that should be all that you needed to comment out

#
#define LED_DDR  DDRB
#define LED_PORT PORTB
#define LED_PIN  _BV(PORTB5)
...
  LED_DDR  |=  LED_PIN; // Enable output for LED
  LED_PORT &= ~LED_PIN; // LED off
...
      LED_PORT &= ~LED_PIN;  // LED off
...
        LED_PORT  |= LED_PIN;     // LED on
gilded gazelle
#

8 lines plus the defines

#

how do you mark code in chat?

obtuse spruce
#

code I'm looking at in the git repo only has those four.... but so long as the ones you are commenting out look like that - all they are doing is blinking the LED - comment them out.

#

to format, type this:
```c++
moo()
```

#

yields:

moo()
gilded gazelle
#

// for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); );

obtuse spruce
#

why are you commenting that out? it doesn't use any of the LED_ defines

gilded gazelle
#

it cave an error after commenting defines

obtuse spruce
#

then you have a different issue - don't comment that out

gilded gazelle
#

ok, looking

#

thank you

obtuse spruce
#

So - here's the thing - notice that that the file you downloaded is a .pde file, not a .ino file - it's really old, and is written for the specific hardware of the Arduino model they wrote that write up for.

gilded gazelle
#

hmmm

obtuse spruce
#

It is accessing the hardware registers directly... and they will not directly translate to the hardware of the SAMD21

#

Now, the good news is that there are nice, common libraries for doing everything it is doing.

#

The LEDstream_CircuitPlayground.ino would be much easier to adapt

gilded gazelle
#

this adalight project is a technical land mine for noobs

obtuse spruce
#

though you'll need to replace all the CircuitPlaygound calls with the library equivalents (CircuitPlayground is a "all-in-one" library for that family of devices)

gilded gazelle
#

ok I will get on it

#

gonna need to spend a month reading libraries I guess....smh

#

I bought the kit because it seemed easier than making my own from the start......I may have been wrong

#

this first bad show from Ada for me

obtuse spruce
#

It isn't that hard:

#include <Adafruit_NeoPixel.h>

#define PIN        6
#define NUMPIXELS 16
Adafruit_NeoPixel myStrip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
...
// then replace
CircuitPlayground.strip
// with
myStrip
#

these are neopixels you've got connected, yes?

gilded gazelle
#

no

#

see my fun now

#

lights from kit

obtuse spruce
#

oh - hrm... why does the CircuitPlayground version of their example code use neopixels then....??

#

okay

#

scratch that

gilded gazelle
#

because they are soldered on the board

#

each version of ledstream is for different leds

obtuse spruce
#

gotcha -

#

wellllllll

gilded gazelle
#

so the old one is what I am stuck using

#

if there was at least a good reference, I miss the days of howtos and rfc's

obtuse spruce
#

so - the old one is written to touch the SPI hardware directly. SPDR and SPSR and SPIF are again, definitions of the hardware registers and bits for the SPI hardware on the Arduino board. Again, those won't map directly the the SAMD21 chip... as it's SPI hw is different. And again, this is all ancient code as there are "standard" ways to do this that work on all boards via the core library.

gilded gazelle
#

yup, Adafruit should delete the entire page and stop selling the rip off kit

#

kit wast lost in mail for 10days and finally arrives to be unusable

obtuse spruce
#

for example, the line of code you had there can be replaced with:

SPI.transfer(testcolor[n + i]);
#

actually - large swaths of that code look like they could be replaced with simple calls.

gilded gazelle
#

thank you for your patience, head spinning,I need a nap.I will be back. I wont be grumpy after short nap with cats

normal bough
#

Hey all having some trouble with the sampling frequency from my MLX90393 magnetometer board. According to the datasheet, using my current settings, I should be able to sample at about 500 Hz. However, I'm only able to get 90 Hz. A few days ago @leaden walrus and @fierce plank gave me some great suggestions about the rate of I2C communication and serial printing speed. I maximized those and it did help a little, but it seems there is still a persistent issue. Does anyone know why reading from the magnetometer would be taking so much longer than it should? For example the read command takes about 10 ms now and the data sheet says it should take about 2 ms using the settings I'm using

fierce plank
#

How many registers of data are you reading each time?

normal bough
#

Not exactly sure what is considered a register, but I'm reading data from an X, Y, and Z axis

fierce plank
#

Aight, so 3x16 bits

normal bough
#

yes

#

I should mention, I increased my I2C clock speed from 100,000 to 400,000 and it increased my speed by about 1 ms, then I increased it to 1,000,000 and it increased it another .1 ms

fierce plank
#

yea that shouldn't take that long. You could maybe try implementing the I2C read functions yourself instead of using the library. Maybe they do some other stuff with delays.

#

Which library are you using?

normal bough
#

hmm, if I check the library for delays and there are none would that cross that off the list?

#

I'm using Adafruits library, which they updated recently after I begged 🙂

fierce plank
normal bough
#

wow, youre right, on another library its 2 ms just like its supposed to be

fierce plank
#

ah nice

normal bough
#

so if I go in and delete all those delays in the library would it work? I don't know much about the hardware side so I don't know if there was a reason they put it in there

fierce plank
#

Haven't looked at the datasheet much, but I guess you could run into reading the same value twice

normal bough
#

well if that's the worst that could happen i'm not too worried about it

#

especially since the other library doesn't seem to be having any issues with it

#

without a delay

fierce plank
#

you put zero into both setFilter and setOversampling, right?

normal bough
#

nope, the data sheet recommends against that, they fastest they say you should do is 0 OSR and 2 dig filt

#

Although, I have no idea why, or if that's actually important, any ideas why they say that?

fierce plank
#

less noisy data I guess.

#

does setting both to zero change the delay?

normal bough
#

hmm, no it doesn't

#

its still the same, 10-11 ms to read the data

#

I commented out that delay and it didn't change it noticeably

fierce plank
#

Oh wait I think I see the problem. The library sets the chip to "Single Measurement Mode", where it goes into idle mode between measurements. So it has to get a signal to go from IDLE to standby, from standby to active, do the measurements and return a value, which takes time. https://github.com/adafruit/Adafruit_MLX90393_Library/blob/master/Adafruit_MLX90393.cpp#L361

normal bough
#

I see, how to change that though?

fierce plank
#

The chip supports burst mode, where it does the measurement, saves it to memory, ready to be read by the microcontroller.

normal bough
#

hmm, is that designed to work continuosly? I plan on reading data at >400 hz for minutes to hours

fierce plank
#

You'd have add some code to the library or use another one. It essentially enabling burst mode by changing some registers in the initialization function, and changing the read function so it reads the raw values directly instead of waiting. If you go to page 28 of the datasheet there's a register map with descriptions etc.

#

yeah it should be fine

#

You're using the breakout board, right? If so it looks like there's an interrupt pin you can use as well. You can change the settings so whenever the sensor has finished making a measurement, it sends a pulse on the INT pin. By setting up an interrupt, you can read the data right as they are available.

#

i.e. no repeated measurements or missed data

normal bough
#

I am using the breakout board

#

If I set up the int pin rather than just fixing what the library is telling the magnetometer to do that would only fix part of the problem right?

fierce plank
#

yeah. Int pin won't do anything now unless you change it to burst mode

normal bough
#

thanks for all this! I really appreciate it!

#

mind taking a look at it from a different angle?

fierce plank
#

what do you mean?

normal bough
#

this library does the sampling speed part correctly, which I just figured out based on your ideas. however, I can't use it because it bugs out when I use it with a multiplexor. but either way this library is doing the reading data correctly, can you help me parse through some things from this library? I don't see where it sets a mode in the begin function, or where it sets a mode, or asks for one when you read data.

#

is it in burst mode and I'm just not catching it?

fierce plank
normal bough
#

afaict? is that just a typo or an acronym I don't understand? And yes, if they just have a call to start it but it isn't used in the begin function or the read function then I don't think you have to be in burst mode to sample >400 hz right?

fierce plank
#

as far as I can tell

normal bough
#

ahhh

fierce plank
#

Not sure tbh

normal bough
#

Well thanks a bunch! really appreciate it. I'll try to figure this out and see what I come up with!

fierce plank
#

no probs

lusty mountain
#

Hello it's me again

#

I hate to keep asking for help, but I have one last thing

#

I'm hoping I can get some help with making the loop at the bottom repeat for 3 minutes when triggered, and then shut off automatically

#
    if (now >= nextFlip) {
      LEDPin1state = !LEDPin1state;
      RPINstate = !RPINstate;
      digitalWrite(LEDPin1, LEDPin1state ? HIGH : LOW);      
      digitalWrite(RPIN, RPINstate ? LOW : HIGH);
      nextFlip = now + activeFlipPeriod;
    }```
#

Can't send the entire code, so heres that. Not sure if that's enough to work with or not

obtuse spruce
#

So - think of it this way: When it is triggered you'll know when you want it turn off... so when triggering add:

if (....) {
  ...
  stopBlinkingAt = now + (3 * 60 * 1000);
  ...
}

and then before the if (blinking) ... you'll need:

if (now >= stopBlinkingAt) {
  blinking = false;
  digitalWrite(LEDPin1, LOW);
  ...
}
#

Also - you'll need to define stopBlinkingAt much the same way you defined nextFlip

gray holly
obtuse spruce
#

But - @gray holly - you seem to have them soldered end-to-end, right?

#

because I don't see separate connections for the strip of 3 or the second strip of 32

gray holly
#

Yes

#

The schematic just cuts it off because it's too long

obtuse spruce
#

so - you really - from the point of view of the code - have one strip of 67

#

how did you declare the strips?

gray holly
#

Yes, it's programmed right, but I can only control the one closest to the board

obtuse spruce
#

code please--- if long, use a pastebin

obtuse spruce
#

sure

lusty mountain
#

@obtuse spruce it works, thanks for your help

obtuse spruce
#

yay!

#

@gray holly --- that code is way to dense to diagnose this problem. You should write a very small sketch that does nothing buy light up the LEDs one by one... so that you can prove to yourself that the HW is working and you can indeed access every light.

gray holly
#

It turns on every light in the strip closest to the board

#

But that's it

obtuse spruce
#

time for you to photograph the connection between the first strip and the short strip of 3

gray holly
#

One sec

#

They have easy connectors

obtuse spruce
#

well - er - so there is a large gap with connectors between these strips? From your diagrams before I gather that power is connected to the far end of the strips - and runs all the way back to power the board.... since that is working, we can assume that your power connections are good.

#

but the data connections would seem suspect...

#

Can you verify connectivity between the data out pin at the end of the first strip and the data in pin at the start of the strip of three?

gray holly
#

It looks fine to me soldering wise

#

Is there a way to verify there's a data signal?

obtuse spruce
#

with an oscilliscope, sure

gray holly
#

I have a voltage checker

#

Does that work?

obtuse spruce
#

welllll... you can probably see voltage on it when there is data - but it'll just be an average....

gray holly
#

Let me try to resolder and see if that helps