#help-with-arduino
1 messages · Page 86 of 1
digitalWrite(pin, LOW)
thanks
No problem
what is the best Arduino for low power aka deep sleep?
Got my display working guys :d
I accidentally had a sneaky line ‘‘delay(100);‘‘
Getting rid of that gives a nice solid image again
Depending on your needs, I use the ATtiny85 and it runs on as low as 0.33 µA if you disable the ADC
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?
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)
I believe so
@rough torrent I'm not clear on what the graph is measuring. SPI runs at 8MHz for the FeatherWing.
Wi-Fi should be able to run faster than that, assuming good signal, server, etc. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-throughput
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.```
The graph is bytes received per sec. I only send once a second, so it's really squished.
@gray holly It looks like you need to download and install the time library from the URL in the comment there.
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
It's a standard C library, though normally it would be uncapitalized, so that's a bit weird to see.
What should I do to fix that?
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
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? 😉
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
Seems you need to reliably transport your data, WiFi is called an unreliable network
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 modeButton A + B: Enter setup
While in Setup: ButtonB -> Increase +1, ButtonA -> Accept/Next
link to the file is https://content.instructables.com/ORIG/F1I/L1NY/K6ZAL3M4/F1IL1NYK6ZAL3M4.ino
So what should I do about stdint
The problem is coming from the DS3232RTC library, so you might want to see if there's a different version of that available?
I was just wondering whether it's because of my horribly written code or the M4 just can't handle receiving 25KB/sec on the SPI bus while also piping that same data through an MP3 decoder. And I'd rather not be tethered to an Ethernet cable. 😅
How do I delete a library?
And it also seems to happen randomly - sometimes I get a good connection for a whole minute, or sometimes I get a bunch 5-second delays.
It can handle that on the SPI bus, wifi is terrible, thats why playing games on wifi stinks, and the ESP32 isnt the fastest at error handling, I would consider this normal behavior, thats why we use reliable data transports like TCP
how are you supposed to make connections to a pro micro board? i find soldering wire into each hole to be incredibly difficult
Could solder headers on it
And use jumpers or a breadboard
female headers are useful for this but hard to find sometimes
Eh, I think male headers gives you more options, a giant pack of jumpers is cheap
well that's not true, stackable female headers can be hard to find
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
@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
I'm not sending anything - just receiving
On the ESP32?
Oh I see, still
In that case, I go back to, wifi is unreliable, and crap
Well, I didn't code it to send any data besides starting the connection to the server
UDP or TCP?
memory buffers are limited. what's driving the once-per-second timing?
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
I'm not explicitly requesting to use UDP and I'm using SSL so I think I'm using TCP
constant bitrate MP3s?
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?
I can't not use SSL - the server I'm connecting to uses HTTPS
what's doing the MP3 decoding?
How would I do so?
And I just restarted my WiFi extender and it's gotten better
Nope, never mind
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
Here's my code: https://textuploader.com/1eb6w
#include
#include
#include "arduino_secrets.h"
#include "Adafruit_M...
I'm just guessing @stuck coral, teamwork ftw!
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
lolololol
Were using SPI, just bump the clock up shell be right
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
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
if not soldered, feather connections can be flaky, those stacked header wires are a bit thin
So I should try like 16 first?
The Featherwing is directly connected to the headers, but my soldering isn't the best.
I'm not convinced that's the key, there's still quite a gap between 25KBytes/sec and 8MHz
I was thinking about adding a buffer of some sorts - was looking into the CirculerBuffer library
Yes, I just want debug info to rule ESP connection issues out
Do I literally just put esp.debug = 2 somewhere in setup()?
Because I don't have an esp object defined.
oh, sorry, my brain is in CircuitPython still, I'll check...
d'oh, there might not be debug in the Arduino lib
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.
Well, found there repo: https://github.com/adafruit/WiFiNINA
Which links to https://www.arduino.cc/en/Reference/WiFiNINA for documentation.
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
there's a debug module, and 3 levels, but I haven't found where it's used https://github.com/adafruit/WiFiNINA/blob/master/src/utility/debug.h
it's probably an Adafruit fork addition nope, it's in the orig Arduino
If this was CircuitPython, we probably could have just done like from WiFiNINA.utility import debug lol
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```
Oh, since I'm streaming MP3 data, I'm not sure. I would try to download a sample, but every time I try, it just breaks the audio file.
I'm streaming from here: https://streams.audio.wgbh.org:8204/classical-hi
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.
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
does this example run? https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
i did, it did the same kind of thing
perhaps the servo is damaged
is there any way to confirm that?
i would expect that example program should run smoothly. do you have another servo?
no, ordered this special for a project
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
ok, will try that. thanks
16MHZ caused an error trying to interface with the ESP32. 12MHZ works and there are less disruptions - albeit more popping and static. (The static only occurs because of a ground loop or whatever it's called - not the SAMDs fault) Still - thanks a ton!
Good evening everyone! I was wondering if anyone could help verify if this circuit looks normal. Could anyone help me by chance?
Actually, would this be more "correct", per se?
missing ground on right 2 LEDs, whats the thing in the middle?
the light sensor is a cds cell?
It's an Ambient light sensor (Phototransistor) . I'm not sure if I know what cds means haha
just wondered if its output is analog or digital
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.
Cadmium selenide, I think. Nope, sulfide, woops.
I put it as input, in my code, though I'm not sure.
cadmium di-sulfide iirc
I have no clue what that is haha... @obtuse spruce Hello again! Would it have the same outcome if I change it?
oh wait I forgot something! Going to repost the picture real quick.
Sorry for the mess heh. (Just added Piezo)
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
would having a J-Link EDU Mini up my microcontrollering? specifically this one: https://www.adafruit.com/product/3571
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
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.
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?
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.
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
Don't feel guilty about outgrowing it. 😉
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
Haha, indeed. The full commercial J-Link is like $600, so be happy for the EDU option...
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
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.
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 };
@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?
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I can say that adding a 32KB buffer does really help with the audio delays 🙂
And it adds another number to display, which makes it cooler 😎
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?)
Also another question I have is how can I add a timestamp to an SD card without using a RTC
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.
@trim hatch what exact boards are you using? are these Unos?
have you added pullups on SDA and SCL lines
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
how come?
ISRs should run as quick as possible
Even serial printing is discouraged inside an ISR
lets do one thing at a time - first add pullups, then test basic i2c connection using the code fro arduino wire example
then how do I use an interrupt to read from wire?
I added the pullups, it didn't make any different
run the basic master/slave example from https://www.arduino.cc/en/reference/wire
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
I tried that a couple days ago it also made no difference
it should be a hardware issue
in any case - first let us get the basic example working, so forget about the sd card and isrs
alright
for hardware, pullups are must
and - did you check which pins are sda and scl on nano?
there are several variations of nano... is it a classic 5v one?
ok
can you test the basic master/slave example from arduino wire reference page?
I'm doing that right now
wow... mini usb port. Haven't seen it in a while
I tried it and it didn't work
that's why i need half a dozen "standard" USB cables 🙂
"good thing about standards is that there are so many to choose from"
yeah mini usb is used on a lot of ftdi stuff too
right now it pretty much just does nothing
if the basic example didn't work, it looks like hardware issue.. how long are the wires? and what value pullups did you use?
i2c is flaky with long wires, but 5 in shouldn't be a problem
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
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?
what else can I try
stupid question - did you put #include <Wire.h> in your code?
you never know ... people sometimes make really silly mistakes - myself included
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
ok. I am out of ideas at the moment, sadly
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
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
yeah I guess
can you use software serial with an rtc?
or wait nvm
anyway thanks again for your help
the rtc i am familiar with use i2c: https://learn.adafruit.com/adafruit-pcf8523-real-time-clock/pinouts
Google up the DATE and TIME macros
you can connect more than one slave device to same i2c bus
two underscores before and after DATE and TIME
huh, anyway I prefer Serial stuff over i2c in general
why @reef ravine
i've heard of DATE and TIME
in c++
but nvm, it'll only give the time & date the program was compiled
thanks for the suggestion
If you prefer serial, then why are you using I2C? Project requirement/constraint?
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
oh ok
I was gonna recommend software serial then but you would have to run it at like 300BPS
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
I can understand lol
it's too much effort to get it set up
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
doesn't that answer my question? lol
I also use a lot of communication stuff
that requires high baud rates
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
Good morning! Regarding about what I was discussing yesterday, could anyone further help me with the code section of the Arduino circuit? Here is the pastbin, with the link of the image of the circuit on the bottom : https://pastebin.com/Xca80TKU .
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@elder hare - did you get it sorted, or do you still need help with that array?
realy need help :/ been stuck at this for hours
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++] = ...)
@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++]);
}
}
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.
oh yea, stupid me
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++!
@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
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
hmm
maybe im doing something wrong somwhere :/
the gradient is not showing up on the strip
Which light library is this?
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]);
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.
no it reads it as
Position, R, G, B
[0,255,255,255]
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
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)
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.
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...
sadly - gotta run - work out time...
sure sure 🙂
where should i start when making a button regonizeable as a joystick/gamepad input on windows?
look for "HID mouse" projects
old-ish example with an analog joystick:
https://learn.adafruit.com/pro-trinket-usb-hid-mouse/example-joystick-mouse
same general idea though
read joystick -> convert to HID mouse messages
you can also do keyboard messages
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
that sounds like the HID library
i misunderstand, i see now, thanks
@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
@obtuse spruce let me know when you are back 🙂
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?
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
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.
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⸮⸮⸮⸮⸮
⸮⸮
Does your serial monitor baud rate match the one set in the code?
Where in the code is the baudrate?
Serial.begin(<baud rate>)
np
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
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?
how are you measuring the time?
rtc module
Serial.println(millis()); directly before and after sensor.readData
You can adjust the time using 6x6 buttons
oh woops, lol you were talking to him
ha! actually that q was for @normal bough
oh lol
that method may be somewhat inaccurate
there could be some overhead from the serial print getting in there
well, I can believe that, but it wouldn't be off by a factor of 5 right?
instead, save to variables and print after
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
@normal bough It is connected using SPI or I2C? if it's i2c you could maybe up it to 400kHz mode
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
its i2c, and I'm not sure the board can do 400kHz, i tried to change it and nothing changed
with Wire.setClock(400000);
you're sort of at the level that can be tricky to sleuth out with simple serial prints
@leaden walrus I mean that its 11 ms between every two samples for minutes on end
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
I'm reading and printing continuously
printing could also slow it down significantly at lower baud rates
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?
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
hmmm
Okay let me look into that and see if it helps and I'll report back after I do
For reference, each "block" in the I2C lines correspond to reading 12 bytes of data which takes 360 microseconds (400kHz I2C)
being able to scope the lines really does help
for real, this is much nicer than having to blink LED's for debugging
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. 😁
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)
I have '840's coming out of my ears, I could poke at it if you can provide some code for me to try?
You would need a Mac too. Haven't others had issues after the connect succeeds?
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
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
thanks anyway, it has crossed the THX-1138 cost threshold and will be put aside 😦
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
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?
Have you tried to rotate it to match the drift? 😛
Sorry, feeling kind of loopy tonight 😁
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.
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
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.
hmmm. Any ideas for finding documentation for how to use another MEM as a reference?
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.
I see, are there any sensors that combine both, specifically to eliminate drift?
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.
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
There's some decent compatibility between the two, since they're made by the same company.
@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
check the work of Kris Winer: https://github.com/kriswiner/MPU6050
he uses madgwicks filter
you can also buy IMUs with data fusion included on the chip - e.g. https://www.adafruit.com/product/4646
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!
@elder hare What happens if you Serial.println(doc["toggleUV"]); ?
gonna try it
@lone ferry im not allowed to print that for some reason
more than one instance of overloaded function "HardwareSerial::println"
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.
this will be some kind of arduinojson class
Ah yes, so println won't have an overload for it unless you cast it. It's probably a string or a boolean.
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
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 😊
Well I've been struggling a bit and I found out that this library doesn't work that well since the last Instagram update 😅
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
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
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?
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
According to the Feather M0 LoRa pinout it would be 10 for the pin number in the code.
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
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?
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
that'll work - the pin out for that is the same
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?
and - er - another quick check - you did initialize the SD card on another computer, right?
yes, using the SD software linked on the Adafruit site even
There's a little copper between the two square pads - that is what should be in tact - visual inspection is probably enough
and I can read this card in another Arduino board (from Wicked Device)
good, okay - then all "obvious things to check" sound good
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)
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.)
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
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
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?
Oh - uhm, I'd think that you'd have the Adafruit SAMD boards installed
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
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
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
Hoping.... hoping... that you mean "Adafruit Feather M0" under "Adafruit SAMD Boards"
no, I wrote the full names out
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
even though I have "Adafruit SAMD Boards" installed in my Boards Manager, it doesn't show up as a sub menu under Tools->Board
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
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+)"
(I'm actually at 1.6.2 and am updating at this moment to see if they moved things around in the menus...)
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
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
You might try installing the Adafruit SPIFlash library - and trying the flashinfo exmample in that one
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
@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
yes but i need to do that automatically ://
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.
yeah i just meant that :// thanks a lot anyway for your help, i was expecting someone to already have solved this in some way
well - is the final goal to have it in Excel?
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 :/
and he wants you to monitor it in real time with an Excel spreadsheet?!??
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:
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
you are using an obsolete begin() API
Your call should look like this:
http.begin(WiFi, Link);
er
wait
You don't have a WiFiClient... see the example https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino
So, somethin glike
// at top of Loop():
WiFiClient client;
HTTPClient http;
// then later in loop():
http.begin(client, Link);
great thanks so much, will try that now. was using example sketch from the esp8266 library so idk why its so outdated
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
(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 ^)
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
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!
Have you selected the Adafruit version of the board from the board menu?
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?
I think the NRF52* boards have TinyUSB by default
This page says its supported: https://github.com/adafruit/Adafruit_TinyUSB_Arduino
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....
Hmm ok, thanks :)
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);
}
}```
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:
- It is doing nothing - the LED is off, the relay is off
- 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
- 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?
Exactly
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.
Thanks for the help!
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
Can you link to your code? I don't see anything immediately wrong in the wiring.
Okay, there's a lot going on in this code. Have you tried something more like a LED test program?
Adafruit will likely have some NeoPixel demo code.
I tried this, and still nothign
I think there's some sort of hardware issue, but I can get voltage from every strip
Is your power supply beefy enough for all of the LEDs?
No, I mean how much current it can supply. Possibly that 5V won't be stable once the LEDs actually turn on.
6 amps so 30 watts
Cool, that should be good for around 100 LEDs at full brightness, assuming they're relatively normal RGBs.
these are neopixels
neopixel is just the name Adafruit gave to WS2812b leds
ohh ok
I thought neopixel was adafruit's brand
What is the problem with these lights then?
no, they (or someone affiliated with them) invented the name - they didn't invent the actual chips
it's a maytag/whirlpool situation. Same washer, different name
can you check that you are connecting data line to the beginning of the strip, not the end?
wdym
neopixel strips are directed
there shoudl be arrows on the actual strip
The schematic you posted shows DIN versus DO.
That would be fine since it's symmetrical
showing direction in which the data travels
power (5v and gnd) can be connected from either end, it deosn't matter
what about data?
the data line shoudl be connected to the beginning of the strip
it is wrong
Good catch, @vivid rock !
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
it does
@cedar mountain thanks... the only way to know what silly mistakes people make is to make them all yourself 🙂
So basically it's only able to run one program at a time, and runs it as soon as it's powered on
yes
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
I feel your pain 🙂
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
both adafruti and sparkfun have nice basic soldering tutorilas
Will I have damaged anything by doing it backwards?
youtube is magical
I'm still having trouble integrating @obtuse spruces code with mine
this stuff is confusing
I'll be back in about 15 min or so
Thanks
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
are all your strips the same direction?
okay - @lusty mountain - I'm back
Is it possible for them to not?
and yes they are
Was just checking, I've made that mistake myself
I'm thinking it's just bad soldering on one of the data things
I'll check back tomororw
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);
}```
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?
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
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)
so loop basically reads the inputs, and controls the outputs depending on what it reads?
right -- and it may set some variables.
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.
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.
It's running right now
(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?
Yes
Cool -- now look at it and see if you understand why
note - every single word there is important. as is the formatting.
Alright, one more step before my project is ready to go!
The strips are 32-3-32
But only the one closest to the arduino can be controlled
@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
The two are isomorphic - they implement the same thing..... but I write mine my way for reasons of clarity:
- you don't need to apply any thought to the
ifclause "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. - 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
- 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
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
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
is nextFlip rolling over a concern as well?
I'm sorry for interrupting
np
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"
current project uses an external RTC for this exact reason
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.
should have been clearer, I'm using circuitpy, an time.monotonic() drifts too much for my taste
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
@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.
okay, so how do I trigger the loop with a button?
Oh, so basically outputs don't need digitalRead? It's just a uneffective / extra line of code?
@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.
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
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!
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?
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?
ohhh, I see what you mean
🙂
unsigned long activeFlipPeriod = flipPeriodSlow;
changes to
unsigned long activeFlipPeriod = flipPeriodFast;
when the button2 says so?
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.
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;
Yes
I'm hoping that you have something like this:
if (digitalRead(button3Pin) == HIGH) {
...
activeFlipPeriod = flipPeriodSlow;
...
}
ohhhhh
in otherwords: "When the button is pressed... ... and set the active flip period to the slow period ...."
along with the other stuff in there
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)
oh okay
And - do you need blinking1 and blinking2 any more?
And - will you need two if blocks at the end to do flipping? or one?
I don't think so
If I learned everything correctly, "blinking" only need to be defined once?
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.
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
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
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
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;
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?
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
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?
I have one
good
Is that the problem?
if (now >= nextFlip) {
ledState = !ledState;
digitalWrite(LEDPin, ledState ? HIGH : LOW);
nextFlip = now + flipPeriodSlow;
}
}
}```
🤦
🥳
Do I need two of those, one for flipPeriodSlow;, and one for flipPeriodFast;?
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
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
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;
}
}```
okay okay
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?
activeFlipPeriod?
tada
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.
sorry for being a bit slow
"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
oh no problem, it's better to learn it, especially if I want to change anything later on
arduino is a bit more difficult than I anticipated
Alright, thanks for teaching me. night
night
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
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.
@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?
I am trying to adapt the arduino #defines to the appropriate qtpy values but cant find the meaning of these lines
// LED pin for Arduino:
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN _BV(PORTB5)
https://learn.adafruit.com/adalight-diy-ambient-tv-lighting/download-and-install
Those are for low level gpio register twiddling... If you are using Circuit Python, why not just use the LED libraries?
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
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.
yeah - that code is the older of the examples and seems to be written for a much older version of the Arduino environment.
commenting out cause error on compile
you have to comment out the lines that reference those values as well
that is a lot of lines
also comment out contents of while's that check the value??
wont be much code left
what?
I got everything commented, let you know
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
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()
// for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); );
why are you commenting that out? it doesn't use any of the LED_ defines
it cave an error after commenting defines
then you have a different issue - don't comment that out
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.
hmmm
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
this adalight project is a technical land mine for noobs
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)
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
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?
oh - hrm... why does the CircuitPlayground version of their example code use neopixels then....??
okay
scratch that
because they are soldered on the board
each version of ledstream is for different leds
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
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.
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
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.
thank you for your patience, head spinning,I need a nap.I will be back. I wont be grumpy after short nap with cats
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
How many registers of data are you reading each time?
Not exactly sure what is considered a register, but I'm reading data from an X, Y, and Z axis
Aight, so 3x16 bits
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
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?
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 🙂
Seems like they use a delay here with a value corresponding to the used setting: https://github.com/adafruit/Adafruit_MLX90393_Library/blob/master/Adafruit_MLX90393.cpp#L366
wow, youre right, on another library its 2 ms just like its supposed to be
ah nice
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
Haven't looked at the datasheet much, but I guess you could run into reading the same value twice
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
you put zero into both setFilter and setOversampling, right?
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?
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
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
I see, how to change that though?
The chip supports burst mode, where it does the measurement, saves it to memory, ready to be read by the microcontroller.
hmm, is that designed to work continuosly? I plan on reading data at >400 hz for minutes to hours
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
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?
yeah. Int pin won't do anything now unless you change it to burst mode
thanks for all this! I really appreciate it!
mind taking a look at it from a different angle?
what do you mean?
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?
afaict they just have a function to call to start burst https://github.com/tedyapo/arduino-MLX90393/blob/4b044b532be969a4464e58fa488459d97248596d/MLX90393.cpp#L147
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?
as far as I can tell
ahhh
Not sure tbh
Well thanks a bunch! really appreciate it. I'll try to figure this out and see what I come up with!
no probs
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
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
Sorry, I was gone at the time. I mean 3 strips of these lengths
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
so - you really - from the point of view of the code - have one strip of 67
how did you declare the strips?
Yes, it's programmed right, but I can only control the one closest to the board
code please--- if long, use a pastebin
sure
@obtuse spruce it works, thanks for your help
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.
I have used another program that is supposed to turn every light available on
It turns on every light in the strip closest to the board
But that's it
time for you to photograph the connection between the first strip and the short strip of 3
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?
with an oscilliscope, sure
welllll... you can probably see voltage on it when there is data - but it'll just be an average....
Let me try to resolder and see if that helps