#help-with-arduino

1 messages · Page 70 of 1

gilded swift
#

This is the temperature sensor I’m using

#

12 bit serial data output over 2 wire i2c

#

Do you think it’s feasible for the attiny25 to handle?

north stream
#

Probably. RAM might be more of a limit than flash.

gilded swift
#

Yeah, that was also something I was thinking about.

#

I suppose the only way to know for sure is to build it and see

north stream
#

That's what I'd do: probably faster than trying to figure it out.

rotund condor
#

Probably

#

Why?

stuck coral
#

The answer is sort of. If you need a webcam buy a webcam. The bitrate will be very poor, and the sensor will not be working in the provided working specifications unless you use a SAMD51 based board but will technically take photos and can send that over USB

#

And the SCCB bus is a pain, some people get it to work over normal i2c but Ive had no joy

narrow jackal
#

Can I use a MOSFET to switch on and off a power supply?

#

Would I need relays?

#

If the max on the MOSFET is 50A and 200V and my power source is 12V 1.5A will it still be compatible

pine bramble
#

is it safe to connect my arduino directly to a power bank? I heard some power banks turn off after some time from low consumption rates but is it possible that a power banks burns the arduino?

narrow jackal
#

anything is possible if it supplies too much voltage/current

#

if it's within 6-12V everything should be good

vast brook
#

fry

narrow jackal
#

But if it's like 6V it might output less voltage than usual

pine bramble
#

its through usb so the voltage should be 5V if im correct

#

but I still don't wanna test it

#

dont wanna kill my arduino mega

vivid rock
#

as long as it is USB, it MUST be 5 V - at most 5.25 - and it is safe to connect to an arduino, no matter what capacity is your powerbank

harsh jackal
#

Completely new to arduino and just bought Elegoo's uno complete starter kit. I've watched a couple videos from BV3d: Bryan Vines to help me get started with setting up a development environment and getting familiar with each part of the kit. I plan on continuing with his series of videos on arduino, but does anyone have other channels or websites that have a complete class.

north stream
#

You can use the Mega's on-board regulator to operate safely from higher voltages. Most USB power banks are okay, but cheap ones can zap things

narrow jackal
#

There's gonna be a voltage regulator it should be a little more

stone dirge
#

New to Arduino Hello, I have a ESP-01s and am trying to figure it out. I uploaded the Blink example and was able to run it perfectly, but when I do the simple BareMinimum AT test, I am unable to get a response. Any thoughts?

safe shell
#

some USB battery packs turn off if the current is too low

north stream
#

That too: there are packs designed not to (they'll run down faster, however)

quartz furnace
#

@stone dirge Does it give errors in the serial monitor ?

stone dirge
#

@quartz furnace No. When I AT test it, nothing is returned

#

Oh btw, I have the monitor set at "Both NW & CR" and 115200 Baud

narrow jackal
#

Can FauxmoESP only be used for simple voice commands?

#

as in "turn device on" or "turn device off"

#

If I were to make an Alexa skill, would I still be able to use FauxmoESP?

quartz furnace
#

@stone dirge hmmm how about a simple Serial Print Sketch .. does it print to the Serial Monitor ?

stone dirge
#

So I tried the "Hello World" example from a booklet that came with a learning kit I bought. It didn't work, but I think I didn't write the code correctly (I likely didn't account for different conditions that the esp8266-01 has).

#

the booklet is for uno/mega 2560

quartz furnace
#

Hmmm since the code is short for a “Hello World” can you post it here ?

stone dirge
#

This is the original, unaltered code:
int val;//define variable val
int ledpin=13;// define digital interface 13
void setup()
{
Serial.begin(9600);// set the baud rate at 9600 to match the software set up. When connected to a specific device, (e.g. bluetooth), the baud rate needs to be the same with it.
pinMode(ledpin,OUTPUT);// initialize digital pin 13 as output. When using I/O ports on an Arduino, this kind of set up is always needed.
}
void loop()
{
val=Serial.read();// read the instruction or character from PC to Arduino, and assign them to Val.
if(val=='R')// determine if the instruction or character received is “R”.
{ // if it’s “R”,
digitalWrite(ledpin,HIGH);// set the LED on digital pin 13 on.
delay(500);
digitalWrite(ledpin,LOW);// set the LED on digital pin 13 off.
delay(500);
Serial.println("Hello World!");// display“Hello World!”string.
}
}

#

mind you I am a complete amateur with this. my only coding knowledge is from a c++ class I took 10+ years ago, so I don't remember anything

#

obviously when I did the code for the esp-01s I adjusted the baud rate and ledpin

quartz furnace
#

How about this sketch to simply troubleshooting

#

void setup() {
Serial.begin(9600);
Serial.println("Hello World!");
}

void loop() {
}

stone dirge
#

should i keep the baud rate at 9600 or 115200?

quartz furnace
#

I’d go with 115200 and edit the 9600 in the pasted code

stone dirge
#

ok

#

so just to be clear, I upload to the esp-01s with the usb adapter set to uart and then reset and flash boot it correct?

#

Okay I just ran the code and nothing is happening

#

led is on, but no response on monitor

quartz furnace
#

Any errors on the Arduino IDE?

stone dirge
#

no errors that i notice

blazing sierra
#

is this something I can use to connect my arduino uno r3 to alexa?

quartz furnace
#

@stone dirge and you are matching the 115200 on the Arduino IDE and in the code ?

stone dirge
#

yes, i think, upload speed is set to 115200

quartz furnace
#

Hmmm and if you go back to the serial port it still has an active connection?

brittle thicket
#

Hey there, I am testing out low power programming on my Feather Lora, (rather unsuccessfully), and saw Ladyada using a usb power analyzer. It was an expensive one, but really handy. I was wondering if anyone knows of cheaper options or even DIY options to get the same capability to see a timeline of power usage via the USB port, or otherwise.

pine bramble
#

is there a way to encrypt or hash using arduini code?

#

is there a cryptography library?

cedar mountain
#

If you have a favorite portable C/C++ library, that can probably be used without a lot of trouble too.

formal onyx
#

I have a 5v 3+amp PSU powering a dozen servos, is it safe to also connect this to the gnd and vin of the arduino to power the arduino? I know the arduino won't draw more than it needs but the servos wont then draw too much power from the arduino, vin is only an input?

cedar mountain
#

On most Arduinos, VIN wants 7-12V, though you can also feed it 5V directly on that pin instead. If the servos overwhelm the power supply, it could brown out the Arduino, but it should otherwise be safe.

quartz furnace
#

Thoughts on if In best practice he should also have a diode since there are servos (motor) ?

cedar mountain
#

That's a good question, and I'm not sure. I haven't generally seen that needed with servos, but hopefully someone with more insight can provide a definitive answer.

pine bramble
#

Small servos can often benefit from a decent sized electrolytic cap across the power leads.

#

Haven't really seen a snubbing diode needed with them, but it's always a possibility.

deep hazel
#

is the only way to get a degree symbol (°) in the Adafruit GFX library basically to draw it manually any time i need one when using the classic font?

north stream
#

With the TFT library, I can use \xf7 to get the degree symbol, that might work with the GFX library too.

deep hazel
#

thanks, i'll give it a shot, typing the symbol into the IDE might be doing some weird unicode one instead of the OG ascii one

formal onyx
#

Yeah I tried using VIN but it does just cause brownouts. I'll have to figure something else out

honest wren
#

I'm trying to play audio off a Seeeduino XAIO, having no luck with circuitpython so far. Also can't do pcm playback with arduino the way I can with a regular arduino chip. Any recommendations on getting audio playback working on this chip?

gusty vault
#

I have two STEMMA Soil Sensors that I just got from Digi-Key and using the sample code I get pretty much 24-26C on the temp, and a solid 65535 no matter what I do for the capacitive measurement. Anyone have any idea what is wrong? Could both sensors be bad?

haughty wigeon
#

What pin on my Feather M0 should I be using to drive my strip of NeoPixels?

north stream
#

Hello, i have an infrared sensor. i connected it to analog pin 0. i used the following code with it to give me the distance. when i put my hand close to it, it gives me 165. when i dont have anything in front of it, it gives me 160. I also tried to adjust the middle distance manipulator but did not make a difference. is this what its supposed to do?```
#define IR A0

int Obstacle;

void setup() {
// put your setup code here, to run once:

Serial.begin(9600);

pinMode(IR, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:

Obstacle = analogRead(IR);

Serial.println(Obstacle);
delay(500);
}```

cedar mountain
#

What's the specific sensor?

north stream
#

ill give you a pic

cedar mountain
#

A part number would be more useful.

north stream
#

where do i find that?

cedar mountain
#

Did you just find it on the side of the road? I presume you bought it somewhere where it was described as a specific sensor device.

north stream
#

i dont remember from where we bought it cause we bought it a real long time ago

cedar mountain
#

Gotcha. So I guess you'll just need to experiment with it, since there's no way to know what it's supposed to do without knowing what it is.

north stream
#

okay

#

and what is the experiment?

cedar mountain
#

🤷

north stream
#

i do not know either

cedar mountain
#

Sorry, I'm the sort of person who reads datasheets and designs things to work that way. I'm not the right person to try to get junkyard gear up and running...

north stream
#

okay

#

ill try and find a way to see which type it is

#

can i DM you when i find which type it is @cedar mountain ?

formal onyx
#

I have one of those

north stream
#

what?

#

the infrared?

formal onyx
#

The infrared sensor. I don't know what it is called, but I know I got it from a mixed bag kit and I should be able to track it down and find the parts list, give me a few minutes

north stream
#

okay

#

thanks

formal onyx
#

I found an identical sensor in an Elegoo sensor kit, but it doesnt have a part number- simply listed as 'tracking' sensor. Sorry :/

north stream
#

can you please test it with the code above and 3 wire connections and let me know if it gives you similar values?

#

please?

formal onyx
#

Yeah sure

north stream
#

this is my connections

#

im not sure if the connections actually worked cause i never tried it before

formal onyx
#

I got very different results

north stream
#

like what?

formal onyx
#

My understanding is that this sensor is not meant to sense distance, only proximity

#

Meaning itll report one value if there is nothing in front of it, and another value if something is

#

Not proportional to its distance from the sensor

north stream
#

okay

formal onyx
#

I got a value of 1023 when nothing is in front of it, and about 23 when blocked by my hand

#

The pot in the middle is used to adjust sensing distance

north stream
#

i already tried adjusting it

formal onyx
#

The red light should not light up when nothing is in front of it

north stream
#

i know

formal onyx
#

If it's lighting up all the time you have to turn the pot counter clockwise

#

If it stays on regardless then something must be wrong with the sensor

north stream
#

okay

#

ill try that

#

i turned it all the way

#

not working

#

led on

#

i think its not working

#

anyways thank you so much

formal onyx
#

No problem, sorry you couldnt get it working

#

Could be too much external lighting? I don't know

dull bison
#

Hey guys, is it possible to get an average value from an analogue input if i measure it for 10 milisec?
I notice in the plotter the value isnt stable so i want to get an average to work with

lone ferry
#

You can always calculate the average yourself.

dull bison
#

k example, does this work?
x = (analogRead(0) + analogRead(0) + analogRead(0) + analogRead(0) + analogRead(0) ) / 5);

#

Is my Arduino gonna take each reading of the analogue input seperatly over time or is it gonna be filled in with the same value

lone ferry
#

You could do it in a loop with a small delay.

dull bison
#

that is A solution

#

im trying to figure out how long it takes for the arduino to measure a single analog reading

#

like, is the arduino fast enough to give me the absolute min val and max value of an analogue reading from a sensor when i touch it. Can i count on it to be accurate? because my plotter shows me a good representation, but if i do the same in the monitor and compare the numbers it looks like it doesnt get the same details

lone ferry
#

If the signal changes from high-to-low-back-to-high in between two calls to analogRead(), you wouldn't read the low value.

dull bison
#

yeah i understand that, but is there a way to figure out the speed it can read it out?

north stream
#

Should be in the IC's data sheet.

lone ferry
#

You could also create a loop that runs for X ms:

long count = 0;
unsigned long startTime = millis();
while (millis() - startTime < 10) {
  int value = analogRead(0);
  count++;
}
Serial.println(count);
dull bison
#

thx, gonna check it out

dull bison
#

around 9 measurements a milisec, if ppl wanted to know

#

Anyone know how to creqte qn unknown sized array. I need an array to stock ints in, but i can never know how many it will be at start of code?

vivid rock
#

if you need not one reading but continuous stream of readings, common approach is using low-pass filter:

float averagedReading=analogRead(0);
while (true) {
    averagedReading=0.7*averagedReading +0.3*analogRead(0);
    Serial.print("New reading: "); Serial.println(averagedReading);
}
#

numbers 0.7 and 0.3 can be changed

north stream
#

You can just create a pointer like c int * arrayPointer; to an array of ints, then use malloc() when you know how many ints you need (but storage on an Arduino is scarce, and malloc isn't very efficient)

#

You'd assign it with something like ```c
arrayPointer = (int *) malloc(num_ints * sizeof(int));

cunning reef
#

If I have a bunch of "if" statements, and I have an "else" statement at the end of my program, how would I address all the variables in the parameters in my "if" statements to tell the "else" loop to run if they're all false?

obtuse spruce
#

There are two common patterns here:

#
if (testA) {
  ...
} else if (testB) {
  ...
} else if (testC) {
  ...
} else {
  ... // runs only if all of testA, testB, and testC are false
}
#

-or you might be after-

if (testA) {
  ...
}
if (testB) {
  ...
}
if (testC) {
  ...
}
if (!testA && !testB && !testC) {
  ... // runs only if all of testA, testB, and testC are false
}
#

In the first case, only the code for the first test that is true will run. In the second, any code for a test that is true will run, and the last one only if all were false.

#

If you want to do the later, but the testX things aren't simple variables (they are expressions), or there are many of them, and you don't want to repeat all that in the final if, you can do this:

#
bool doDefault = true;
if (testA) {
  doDefault = false;
  ...
}
if (testB) {
  doDefault = false;
  ...
}
if (testC) {
  doDefault = false;
  ...
}
if (doDefault) {
  ... // only run if any of the above didn't run
}
#

Hope that is what you were looking for, @cunning reef

cunning reef
#

Yes, the second one is exactly what I want to know. Thanks!

dull bison
#

if you need not one reading but continuous stream of readings, common approach is using low-pass filter:

float averagedReading=analogRead(0);
while (true) {
    averagedReading=0.7*averagedReading +0.3*analogRead(0);
    Serial.print("New reading: "); Serial.println(averagedReading);
}

@vivid rock
Thx im gonna give it a try

#

You'd assign it with something like ```c
arrayPointer = (int *) malloc(num_ints * sizeof(int));

@north stream thx for clarifying

#

Is there a clean way to check for the highest measured value of an analogueRead in a certain timewindow. I now check if my current value is bigger than previous and keep doing that

north stream
#

That's how I do it

dull bison
#

yeah i figured, but there might have been some function that does it for me i dont know bout

lost kraken
#

Would using an arduino to make a controller using HID be the same as a regular controller?

slow nebula
#

qucik question... if i connect a LED to a 3.3V of my arduino.... do i have to put a resistance to protect my arduino ? (the LED was previously powered by 4.5V aka 3*LR41 battery)

obtuse spruce
#

Er, you need a resistor to protect the LED.

gilded swift
#

At least a 20ohm resistor at that

#

If it’s blue/green LED. Probably a 100ohm for red/yellow

formal onyx
#

Can I use any bluetooth receiver board to control an arduino nano with a ps4/bluetooth gamepad? In guides I can find online they use boards with a USB port, and a USB bluetooth receiver. But I would rather use something like the HC-05 because it is much smaller and doesnt require an external receiver.

gilded swift
#

I’m sure there is a way

formal onyx
#

Nevermind, I finally got my esp32 working so im moving to that now

gilded swift
#

I think the biggest issue is you are not setting your data pin in the Arduino code for output

celest sequoia
#

@gilded swift you're talking to me?

gilded swift
#

Just do pinMode(DATA_PIN, OUTPUT)

#

Yeah

#

I’m not aware of FasLED library sets pin mode or not

celest sequoia
#

i dont quite get wwhat yo're saying

#

sorry, its my firsrduino project

#

it's my first arduino project*

gilded swift
#

You’re okay let me look at your code based on the example on the github page

celest sequoia
#

Heyguys, for some reason my leds don't light up. This is 12 second move of my circuit, and this is the code:

#include <FastLED.h>

#define LED_TYPE WS2812B // type of RGB LEDs
#define COLOR_ORDER GRB // sequence of colors in data stream
#define NUM_LEDS 9 // 60 LEDs numbered [0..59]
#define DATA_PIN 6 // LED data pin
#define BRIGHTNESS 200 // brightness range [off..on] = [0..255]

// Define the array of RGB control data for each LED
CRGB leds[NUM_LEDS];

void setup() {

// initialize library using CRGB LED array
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);

}

void loop() {

// configure some LEDs by direct RGB level setting
leds[0] = CRGB(255, 0, 0);
leds[1] = CRGB(0, 255, 0);
leds[2] = CRGB(0, 0, 255);

leds[3].r = 128;
leds[3].g = 75;
leds[3].b = 170;

leds[4].setRGB(50, 100, 150);
leds[5] = 0x08FFA7;

FastLED.show();
delay(1000);

}

What can be the problem ? Honestly, i'm outta ideas

gilded swift
#

Try changing LED_TYPE to NEOPIXEL, and remove color order

#

Oh and can you put your code between 3 ` on each side so it formats better

vivid rock
#

and indeed, add in setup

pinMode(DATA_PIN, OUTPUT);
celest sequoia
#

disregard first photo xD

gilded swift
#

        CRGB leds[1];
        void setup() { FastLED.addLeds<NEOPIXEL, 6>(leds, 1); }
        void loop() { 
                leds[0] = CRGB::White; FastLED.show(); delay(30); 
                leds[0] = CRGB::Black; FastLED.show(); delay(30);
        }```
#

Try that code

celest sequoia
#

erase everything and try yours?

gilded swift
#

Just comment it out

celest sequoia
#

which part should i comment out?

#

everything?

gilded swift
#

Block comment your entire code, and paste that code in

#

/** block comment example */

formal onyx
gilded swift
#

Have you downloaded the libraries? @formal onyx

formal onyx
#

The ESPAsync yes, WiFi (should be?) included in the IDE already

gilded swift
#

Always good to double check

celest sequoia
#

@gilded swift nothing

#

:/

#

probably hardware failure?

gilded swift
#

Did you download the FastLED library @celest sequoia

celest sequoia
#

yeah

#

of this im sure

gilded swift
#

Okay

formal onyx
#

But yes it is definitely installed, it is available in sketch > include library > contributed libraries

gilded swift
#

And you’re positive you’re hooked up to D6?

celest sequoia
#

Yeah

gilded swift
#

Hmm okay

celest sequoia
#

I mean, ive changed the pin to 12

#

But ive also changed your code

#

any ideas?

#

@gilded swift

gilded swift
#

I’m looking to see what might be wrong

#

But I think you still might need to add pinMode(DATA_PIN, OUTPUT)

celest sequoia
#

its not my only led strip, as well as arduino

#

so ifthey are a problem, its no problem at all

gilded swift
#

Maybe swap them around

celest sequoia
#

@gilded swift there re 2 GND pins,should i connect the ground tothe pin on the D (digital probably?) row or, the one closer to 5V

gilded swift
#

either ground pin works

honest wren
#

Does anybody know if there is a PCM playback sketch that will work on the SAMD21?

celest sequoia
#

@gilded swift still doset work

#

another arduino

#

another led strip

gilded swift
#

hmm

north stream
#

I'm not sure what you mean by "PCM playback" here. The SAMD21 does have an analog output.

bleak raptor
#

Not sure if this should go here or in #help-with-radio, but do you guys know if the receiver in this project can be modified to work with a standard RC transmitter? I'm thinking of doing an RC car project. The receiver is about halfway down the page.

https://www.rcpano.net/2020/04/09/how-to-make-6-channel-radio-control-for-models-diy-proportional-rc/

cedar mountain
#

That's unfortunately a completely different radio frequency range and data protocol, so you'd need a different receiver rather than the nRF24L01 used here.

stone dirge
#

Anyone awake to help a beginner? I'm having trouble with IRRemote library and "USECPERTICK"

#

I have version 2.6.1 installed for the library

#

Please DM if you can help

#

Error message:

#

In function 'void dump(decode_results*)':
BareMinimum:65:39: error: 'USECPERTICK' was not declared in this scope
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
^~~~~~~~~~~
BareMinimum:69:46: error: 'USECPERTICK' was not declared in this scope
Serial.print (-(int)results->rawbuf[i]*USECPERTICK, DEC);
^~~~~~~~~~~
Using library IRremote at version 2.6.1 in folder: D:\vinhm\Documents\Arduino\libraries\IRremote
exit status 1
'USECPERTICK' was not declared in this scope

#

Project 14: IR Remote Control

storm harness
#

I'm trying to figure out the code I would need to do this:

#

When given a value eg 1.7 , the rounded down value (1), rounded up value (2) and decimal part (0.7) are produced

lone ferry
#

You can use floor(1.7) to get 1, ceil(1.7) to get 2. I'm not sure if there is a function to get the decimal part, but you can do 1.7 - floor(1.7).

storm harness
#

1.7 - floor(1.7) should work right?

lone ferry
#

Not sure if it works when the number if negative, but if positive it should.

storm harness
#

the number will always be positive so this should be ok, thanks for the help @lone ferry

obtuse spruce
storm harness
#

I'm looking to crossfade between 2 audio sources, but have it so the crossfade value can be any float. For example a crossfade of 0.5, would fade evenly between source 1 and source 2, while a crossfade of 42.5 would also fade evenly between 1 and 2.

storm harness
#

okay I've figured it out : )

north stream
#

@stone dirge I'm guessing those instructions were written for an earlier or different version of the IR remote library. The current Ken Shirriff / z3t0 version appears to use MICROS_PER_TICK instead of USECPERTICK.

obtuse spruce
#

@storm harness - I'm curious what you came up with here... I'm not sure I can make sense of a function where crossfade values of both 0.5 and 42.5 make sense.... out of what range?

#

I mean - how could BOTH of those values mean an even fade?

storm harness
#
  ammount = ammount - (int) ammount;
  //convert to modular number space
  if(ammount < 0.5)
  {
    gain1 = ((-2 * ammount) + 1);
    gain2 = (2 * ammount);
  }
  else
  {
    gain1 = ((2 * ammount) -1);
    gain2 = ((-2 * ammount) +2);
  }
}
north stream
#

I'd guess those are rates/times

storm harness
#

something like this

#

amount is the crossfade level

cedar mountain
#

The factors of 2 in the above code seem weird to me. Ordinarily I'd expect to see just x and 1-x if x is a crossfade ratio.

obtuse spruce
#

So, considering just the fractional part of the float, you want from 0 to 0.5 to fade from all gain1 to all gain2, and then from 0.5 to 1.0 you want to fade back from all gain2 to all gain1?

#

(that is what your code does, I think)

storm harness
#

yeah, you're correct

#

I couldn't come up with a way to crossfade except that

#

other ones dont repeat nicely

obtuse spruce
#

What are you trying to get? From 0.0 to 1.0 gives fade from gain1 to gain2?

#

Oh - you do want it to repeat

storm harness
#

yeah that is what i was trying to do

obtuse spruce
#

okay - you're good then!

lone ferry
#

Note that you can also do this with a sine / cosine function. Then the amount of crossfade isn't linear but that may actually look nicer.

cedar mountain
#

You might also consider doing an even/odd function, where 0 is source A, 1 is source B, 2 is source A, etc. That way every 0.5 is an even mix.

storm harness
#

this is for wavetable interpolation not for audio, so it has to be done linearly.

#

@cedar mountain while it is a bit of a botch fix, i just multiply the input by 0.5 and it works.

stone dirge
#

@north stream Thank you, I will try doing a little research on micros_per_tick

#

@north stream Would it be a simple as replacing USECPERTOCK with MICROS_PER_TICK?

north stream
#

quite possibly

stone dirge
#

thank you, i appreciate the help

stone dirge
#

Another question, if anyone is available to help. I have an ESP-01s (https://www.microcenter.com/product/615098/inland-esp-01s-usb-to-esp8266-wireless-adapter-module) I bought from micro center, I have the board installed into arduino ide (http://arduino.esp8266.com/stable/package_esp8266com_index.json) and I am using the included USB adapter in UArt mode to upload code and Flash download mode to monitor the program. My question is:

#
  1. I am not getting a response when using the AT command with the BareMinimum program. Any thoughts
#

I have the monitor set to Both NL & CR at 115200 baud rate

#

I also have the upload speed set to 115200 in the ide

#
  1. I also tried uploading and running the Blink example, which worked perfectly.
#
  1. I don't know why I used numbered bullet points as I only have one question haha
twilit hare
#

does anyone know of any examples of playing audio with a PyPortal using ARDUINO? [Update - found some info on the adafruit website - looks like they don't suggest using the audio with Arduino... so maybe I'm gonna be forced to build this project in python after all) 🙂

wintry igloo
#

im using the adafruit feather motorshield, im struggling with the sample code, when the motor is triggered im wondering how to control how long it runs

#

my Motor->run(FORWARD)

#

im trying to use the feather to connect to adafruit.io to open and close my chicken door :\

#

ive got the hardware all figured out 😛

#

does anyone know of any documentation that could help?

cedar mountain
#

The simplest method would be to use a delay, then stop the motor: myMotor->run(FORWARD); delay(1000); // 1 second myMotor->run(RELEASE);

wintry igloo
#

1000 is one second, awesome!

#

milliseconds, duh

#

Thank you!

#

i might be able to figure this out!

wintry igloo
#

im missing something though

#

it was " if(data->toPinLevel() == HIGH)"

#

i dont really understand the data conversion from the io.

north stream
#

It looks like you have two problems. One is you're handing in a pointer to an object, but checking if it's 0 or 1 (unlikely: you probably want to access an instance member or call a method). The other is that you're using the assignment operator = instead of the comparison operator ==

wintry igloo
#

I think i cant have my adafruit.io switch say open/closed it has to be 1 or 0

#

but it doesnt like the second IF

#

is what i had from the sample

#

:\

north stream
#

I don't understand why you changed it.

wintry igloo
#

i dont understand the code :{

bleak raptor
#

@cedar mountain thanks! Do you know of any projects that are compatible with a standard RC transmitter? Most of the ones I see are designed like that one, with a custom transmitter.

wintry igloo
#

i changed it back

#

*sweat

#

oh wait it compiled this time!

#

how does it change 1 or 0 to low or high

north stream
#

The Arduino code has definitions for "LOW" and "HIGH"

wintry igloo
#

everytime i press the button it just goes back and forth

#

instead of one way only

north stream
#

@bleak raptor ordinary RC protocol is a special case of PWM.

bleak raptor
#

Alright 🤔

north stream
wintry igloo
#

oh sorry i mean it seems to run both instances of the IF

#

it does the 1 task then the 0 task

#

i dont need pinlevel, can i just do a IF that checks the feed data?

#

¯_(ツ)_/¯

#

can i use IF and a specific value like 1, 2 or 3, not high vs low?

obtuse spruce
#

yes if (data == 3) ...

wintry igloo
#

hmm it complained about that when i did it

#

i think i fixed it by adding int reading = data->toInt();

north stream
#

data is still a pointer to an instance, not an integer. Comparing or casting it to integers is unlikely to do what you want

obtuse spruce
#

what is the type of data?

#

AdafruitIO_Data* I see, so it is a point to something

#

ah - so, AdafruitIO_Data is "opaque" in the sense that you can't just simply reach in and grab the low level data... You must ask it for the data.

#

so something like if (data->toInt() == 2) ...

#

Now, it turns out "to be helpful" a value received this way can be coverted to any number of basic types.

#

You can call:

toBool()
toInt()
toPinLevel()
toDouble()
toRed()
....
#

There are a zillion of them. Now, which one to use depends on what data you think you are expecting. If you are expecting an integer - than use toInt().... if you are expecting a pixel color, try toNeoPixel()

#

If you are expecting a boolean value, you can use toBool()... or the even cleaner isTrue() and isFalse() -- like so: if (data->isTrue()) { .... }

#

Of course, the data sent by the other side will have to be in some compatible format.... So if the other side of the project is sending HIGH and LOW, then by all means use toPinLevel() -- If the other side is sending integers as a sort of stand in for commands ("1 means close, 2 means open, 3 means flash the lights, 4 means dispense kitty treats, ....") --- then use toInt() and test as we suggested.

#

Hope that makes some sense.

wintry igloo
#

thank you all so much!

#

i think i got it!

#

i changed the if statement around, it seems to work better too

#

if (action) else (non action message)

#

im testing it in the coop now

obtuse spruce
#

in the coop... I suppose I should have said "4 means dispense chicken treats...." 😁

wintry igloo
#

haha maybe ill have cat treats as a deterrent to pests

#

thanks!

wintry igloo
#

this works well 😄

#

working so far

#

😄

#

whats the worst that could happen....

tame temple
#

hi everyone, i'm new here

#

i need some help about arduino code ( i'm still a beginner )

#

i'm doing a project using:
LCD 16x2 ( changed from LCD keypad shield )
AS608 Fingerprint Sensor
4 Relay 12volt
arduino nano
4 buttons
and 4 solenoid locks

#

i'm sorry if i'm using the wrong chat

obtuse spruce
#

okay - what's the help you need....

#

(first thought: that is a lot of code for a single file.... should probably be split up)

tame temple
#

i'm a beginner so i don't know how to split it up

#

anyway

#

i shouldn't have put that one first but

#

i was using an Analog pin to control 4 buttons

#

and change the display screen on LCD up, down, right, left

#

but now i need to changed it to a different pins ( digital pin )

obtuse spruce
#

I see, your problem is here:

#
int up_hit = digitalRead(up);
int down_hit = digitalRead(down);
int right_hit = digitalRead(right);
tame temple
#

so i need help to make the button do the same thing as the analog pin

obtuse spruce
#

You see - when this code runs - the button states are read once, and the value saved in each of those three variables.

#

Later - when you this code runs:

int evaluateButton(int x) {  
    if (right_hit == LOW) {
    x = 1; // right
    } else if (up_hit == LOW) {
    x = 2; // up
  } else if (down_hit == LOW) {
    x = 3; // down
  } 
  return x;
}
tame temple
#

i want to clarify that

obtuse spruce
#

It is not testing the current state of the pins, but instead, the state of the pins at the time up_hit etc. were initialized.

tame temple
#

this is the original one:

readKey = analogRead(0)
button = evaluateButton(readKey)

int evaluateButton(int x) {
  int result = 0;
  if (x < 50) {
    result = 1; // right
  } else if (x < 195) {
    result = 2; // up
  } else if (x < 380) {
    result = 3; // down
  } else if (x < 790) {
    result = 4; // left
  }
  return result;
}
int evaluateButton1(int x) {
  int result = 0;
  if (x < 50) {
    result = 1; // right
  } else if (x < 195) {
    result = 2; // up
  } else if (x < 380) {
    result = 3; // down
  } else if (x < 790) {
    result = 4; // left
  } 
  return result;
}
obtuse spruce
#

that was not right, either. (assuming that that is at global scope)

#

also, this line is not doing what you think:

    button = evaluateButton(readKey);
#

So, let's go back to

int up_hit = digitalRead(up);
tame temple
#

ok

obtuse spruce
#

What this line of code means is this: "When this line is executed..... call the function digitalRead with the argument up which will read the state of the hardware pin and return a value, HIGH or LOW. Then create a variable named up_hit and initialize it's value to that result."

#

Let's start with that - is my description clear?

tame temple
#

yes

#

your description is clear

obtuse spruce
#

Good. Now, if this line were in a function, like this, say:

void loop() {
  int up_hit = digitalRead(up);
  ...
}
#

Then it would be executed once each time the function was called.

#

But in your code, that line is outside of any function. We say this is "global". And that means the line code is executed once at the start of the program (somewhat before setup() is called).

#

It will only ever be called once, and in this case before you have even set up the pins in setup()!

#

Does that make sense?

tame temple
#

yes

obtuse spruce
#

So - rather than writing

    if (right_hit == LOW) {

you should be writing

    if (digitalRead(right) == LOW) {

which will execute the call to digitalRead() each time that if statement is executed, thus reading the pin afresh.

#

Do you see how the existing code wouldn't ever look at the pin after the start of the program.... whereas the second version will re-read the pin each time?

tame temple
#

hmmm.. yes

obtuse spruce
#

It is important to get the "operational model" of how C code works in your head: Saying x = .. some thing else ...; is not like regular math: Later when you use x, it is not the same as the "some thing else" - At the time the assignment (x = ...) was executed x was set to the result of executing the some thing else.... then later when you use x, you are using that stored value. No matter if "some thing else" would now be different, x is the stored value until another assignment is executed.

#

Of course, if the program executes x = 3 + 4; Then later, using x is exactly the same as using (3 + 4) -- because the value of 3 + 4 can't ever change.... The difficulty comes in with expressions that can: digitalRead() depends on the state of hardware that can change. millis() depends on the state of timers... and in x = 10 * y; the expression 10 * y might change if y changes!

#
void setup() {
  int y = 5;
  int x = 10 * y;
  Serial.begin();
  while (!Serial);
  Serial.println(x);
  y = -2;
  Serial.println(x);
  y = 10000;
  Serial.println(x);
}

All of those print 50... because the value of 10 * y was evaluated and stored in x on that one line at the top... no matter that y changed later... x was only assigned to once.

#

Does that help clear up what was wrong with the way the pins were read?

tame temple
#

yes i understand

obtuse spruce
#

great!

#

okay - one more thing

#

You have code like this:

   button1 = evaluateButton1(readKey1);

and later this:

int evaluateButton1(int x) {
    if (right_hit == LOW) {
    x = 1; // right
    } else if (up_hit == LOW) {
    x = 2; // up
  } else if (down_hit == LOW) {
    x = 3; // down
  } 
  return x;
}
tame temple
#

ye, i wasn't understand how the original code works

#

since everything was putting all of it into a variable name: result

obtuse spruce
#

When you pass a value like that (readKey1) to a function declared like that (int x) -- the function cannot change the value of the variable in the caller. In this case, evaluateButton1 cannot change readKey1.

#

Okay, It should look like this:

   button1 = evaluateButton1();

and

int evaluateButton1() {
  int x;
  if (right_hit == LOW) {
    x = 1; // right
  } else if (up_hit == LOW) {
    x = 2; // up
  } else if (down_hit == LOW) {
    x = 3; // down
  } 
  return x;
}

which can be simplified:

int evaluateButton1() {
  int x;
  if (right_hit == LOW) {
    return 1; // right
  } else if (up_hit == LOW) {
    return 2; // up
  } else if (down_hit == LOW) {
    return 3; // down
  } 
  return 0;
}
#

(er - replacing all the right_hit like things with the digitalRead function calls as described above)

tame temple
#

ye

#

already did that

obtuse spruce
#

Also evaluateButton and evaluateButton1 are identical - no need to have both!

#

okay - bed time for me... Good luck!

tame temple
#

ok

#

Good night

quartz furnace
#

Good morning all. Need help with adding to an array " char txtMsg[200];"

#

I have a RTC and I wan to add the .hour + .minute + .second at the time of the message before sending

#

too many arguments to function 'char* strcpy(char*, const char*)' << Is my error

#

strcpy(txtMsg, "cat" + clock.hour, DEC); < is a snip of the code line

#

RTC is the DS1307

cedar mountain
#

Several things are going wrong there, I think. For one the DEC parameter is only used in the Arduino print routines, not the general C str library calls. The use of + is likely not doing what you expect with character arrays, since it's actually performing pointer arithmetic. And strcpy doesn't concatenate, just overwrites... you'd want strcat for that instead.

#

But it looks like you would want sprintf() in general for this kind of operation, where you want to construct a string from placeholder text plus numeric variables.

quartz furnace
#

okay looiing into strcat() ughhh Not the best with Strings/Char/Arrays etc

obtuse spruce
#

try something like:

snprintf(txtMsg, sizeof(txtMsg), "cat%2d.%02d.%02d", clock.hour, clock.minute, clock.second);
#

Some notes on this:

  • always use snprintf, never sprintf (makes sure you don't overrun your buffer
  • the %2d means a two character wide decimal field, %02d means the same, only zero padded, %d would be just decimal, as small as needed
  • replace the d with x for hexadecimal
  • I believe that not all Arduino core libraries have a full implementation, and may not support all the features of the --printf family of functions... though they will support the above.
quartz furnace
#

ahhh it worked

#

now if I want to put a space after "t" in "cat" do I need to put a "%" someting before the %2d ? I just can't put a space like this "cat %2d......."

obtuse spruce
#

just put in a space!

#

The format string is just copied into the buffer, but replacing each % field descriptor with the next argument from what you passed.

quartz furnace
#

Works .. just seems like it takes longer to send

#

actualy, the same.. must have been a random delay by the cell network

obtuse spruce
#

I'm not sure where or how you're sending it - but the difference between using snprintf and other ways of building up that string are minuscule.

quartz furnace
#

It is working just fine now, Appreciate the help.. Have it exactly doing what I want

obtuse spruce
quartz furnace
#

Yeah that would be very helpful.. I was using "sprintf(txtMsg, "%02d:%02d:%02d", clock.hour,clock.minute,clock.second, " cat");" Before you jumped in to help

#

It was not printing 'cat' but did the time

obtuse spruce
#

yes, you'd need a %s specifier if you want it to include a string from the argument list... but if that string is fixed (like "cat") you might as well just put it in the format string.

quartz furnace
#

Gotcha... Off to read the link you sent now and getting some lunch .. Thanks again @obtuse spruce It is wokring 100% perfect

obtuse spruce
#

welcome

safe shell
#

@obtuse spruce snprintf looks handy, I wonder what Arduino Serial.print() uses under the hood

obtuse spruce
#

I believe that the Arduino cores have a Serial print functions are all just hard coded for each type. The Adafruit cores add Serial.printf which uses vsnprintf under the hood.

#

(the v version is just variant that allows one var-args function to call another)

pulsar yacht
#

Hello this is my firs message in this server, so first of all thanks, and sorry if my English is not very well.
I have some issues working with the AdafruitIO and the PubSubClient library running on the esp8266. I read in the adafruit webpage that is compatible.
The connection is correct because I can see the information published with the esp8266 on the dashboard, and I receive correctly the messages from the adafruitIO to the esp8266. The problem is that after a little time, appears “failed, rc=6 try again in 5 seconds”, then reconnects again, and repeat this situation. Sometime reconnect immediately, and sometimes no.
Someone know what the problem is?
Thanks

stuck coral
#

Do you have a link to which fork of pubsub youre using? The usual version does not have a state value of 6

jovial heart
#

i am starting out with Arduinos and i know a a little bit about programming and is there any good tutorials on programing a Arduino

north stream
pulsar yacht
#

Do you have a link to which fork of pubsub youre using? The usual version does not have a state value of 6
@stuck coral i installed the library directly from arduino library manager

#

but i read on som github issu that the 6 will be coming from the adafruit broker, not the client

pulsar yacht
#

I changed the clientID and for now is working....

wraith current
#

@pulsar yacht good catch. That happened to me too. Gotta use a real unique I'd when on a server with many other users.

pulsar yacht
#

@pulsar yacht good catch. That happened to me too. Gotta use a real unique I'd when on a server with many other users.
@wraith current It's strange because i have connected only one esp8266, but now its working...

wraith current
#

@pulsar yacht my point is that you're not the only one connecting to that mqtt broker

pulsar yacht
#

@pulsar yacht my point is that you're not the only one connecting to that mqtt broker
@wraith current ahh okay. I thought that i was the only because i was working in my account with only one esp. Thanks!

wraith current
#

@pulsar yacht the mqtt broker keeps track of every device based on it's id.

stone dirge
#

Can anyone help me with setting up a circuit for controlling an led with my esp-01s?

#

I have 3.3v and ground from mega 2560 going to vcc and ground of the esp-01s

#

gpio1 from esp-01s going to positive of led and negative of led going to ground

reef ravine
#

you'll need a current limiting resistor in series with the LED

stone dirge
#

220 ohm ok?

#

@reef ravine can you confirm that the gpio1 is pin 2 on the esp-01 module? Im not sure

reef ravine
#

220 would give you about 5 mA

stone dirge
#

would you recommend using a smaller or bigger resistor?

reef ravine
#

what color LED?

stone dirge
#

red

gilded swift
#

Red/yellow on 3.3V would need a larger resistor than blue/green. 300-330 for red/yellow, 220 is good for blue/green

reef ravine
#

The forward voltage drop of different colors is different

stone dirge
#

1k or 10k?

#

btw i am very much so a beginner at this, so sorry for the lack of knowledge

reef ravine
#

For red then you have 3.3v - 2.0v = 1.3v. 1.3v / 220 ohms = 6 mA

stone dirge
#

ok so using a blue led with 220 ohm would be ok?

gilded swift
#

You could do 220 on red, it just might be brighter than you need

stone dirge
#

this is purely experimental, so it doesn't need to be red

gilded swift
#

6mA across a red is considerably brighter than 6mA across a blue

stone dirge
#

im just trying to learn

gilded swift
#

Try out both and see which you like best

reef ravine
#

the key point is you need to limit the current being drawn from a pin on any MCU

stone dirge
#

ok so trying it with neither the blue nor red work with the 220. I'm assuming that I don't have it setup right

reef ravine
#

do you have a multimeter?

stone dirge
#

yes

reef ravine
#

is the pin actually going high?

#

or perhaps the LED is wrong way around

stone dirge
#

i have the small pin on the led connected to the resistor which is going to ground

#

the longer pin is going to the gpio1 pin on the esp01

reef ravine
#

the shorter lead is generally negative so that sounds correct

#

are you using a breadboard?

stone dirge
#

yes

#

the breadboard is being powered by a mega2560 because i don't have a seperate power supply to power it

reef ravine
#

if you measure GPIO1, is it high?

stone dirge
#

positive on the breadboard is going to 3.3v, and ground to ground

reef ravine
#

sounds like a good way to power the ESP01

stone dirge
#

~2.3v

#

change my mind, measured wrong pins. is actually about 1v

reef ravine
#

does it go to 3.3 if you remove the LED and / or the resistor?

#

for that matter, is Vcc to the ESP actually 3.3v?

stone dirge
#

does not go up to 3.3

#

not sure

reef ravine
#

i'd measure from Vcc to ground at the ESP and make sure it is being properly powered

stone dirge
#

vcc to ground is 3.3

#

would you like to see my code?

reef ravine
#

ok, if unconnected then GPIO1 should be 0 or 3.3v

#

if it is short you can paste it here, use the "backtick" to format it like this

stone dirge
#

its neither, im getting about 1v

#

60 lines ok?

reef ravine
#

are you connected via serial to the ESP? it uses GPIO1 for serial TX

stone dirge
#

there is also a config tab if you need to see that

#

its an adafruit io example btw

#

the coding was uploaded to the esp via a separate adapter

reef ravine
#

first thing i notice is you have #define LED_PIN 2, "which pin is which" varies from board to board

stone dirge
#

I honestly am unsure

reef ravine
#

try changing the define to pin 3 and connect to GPIO2

stone dirge
#

ok i'll do that now

reef ravine
#

pin 2 is being used the serial interface

#

the ESP01 seems to have a limited number of IO pins compared to other variants

stone dirge
#

even though im just using the mega as a power supply, do i need the rx tx pins connected? or is that just for uploading?

reef ravine
#

Tx and RX are used for serial programming, using the mega as a convenient 3.3v power supply is fine

stone dirge
#

ok

#

so i should change the code to #define pin 3 as well as all LED_PIN to pin 3?

reef ravine
#

#define LED_PIN 3 means "substitute 3 wherever LED_PIN appears in the code"

stone dirge
#

ah i see

reef ravine
#

it's handy so if you decide to use a different pin you only need to change your code in one place

stone dirge
#

ok uploading now

#

ok so now gpio2 is pulling 0v but I cant seem to get it to pull high

reef ravine
#

with nothing connected to GPIO2?

#

(which is pin 3 btw)

stone dirge
#

the mega is not outputting power...

reef ravine
#

bad connection?

stone dirge
#

no im just dumb... lol i had the multimeter on ac... power is fine

reef ravine
#

so does pin 3 toggle between 0 and 3.3v?

stone dirge
#

no only 0v

reef ravine
#

if you move the LED to Vcc, does it glow?

stone dirge
#

yes

reef ravine
#

ok, so that is wired OK

#

what do you see on the serial terminal?

stone dirge
#

what do you mean?

reef ravine
#

are you using the Arduino IDE?

stone dirge
#

yes but the esp is not currently connected to that

#

im trying to control it through adafruit

#

sorry i probably should have led with that

#

i did confirm that it is connected

#

using the included usb adapter

reef ravine
#

the serial terminal will show diagnostic messages (all the "Serial.print" statements)

stone dirge
#

so then should i connect the tx rx on both boards to eachother?

reef ravine
#

what did you mean by "included usb adapter"?

stone dirge
#

thats how i uploaded the code

reef ravine
#

ok, then after upload you transferred to the breadboard?

stone dirge
#

yes exactly

reef ravine
#

it might pay to wire the adapter to the breadboard so you have power and serial from it, then you don't need the mega for power

stone dirge
#

honestly have no idea how to even get started on that lol

reef ravine
#

you would wire it one to one, the pins on the ESP to the corresponding socket on the adapter, all you need are Vcc and ground, Tx and Rx

stone dirge
#

oh i see

reef ravine
#

that way you still have access to the pins and you can use the serial monitor to help debug

stone dirge
#

i'll go ahead and try that now and i'll get back to you

reef ravine
#

come to think of it, how are you mounting that module on a breadboard? either rows or columns will be shorted....

stone dirge
#

i have male to female leads

reef ravine
#

ah, ok

stone dirge
#

ok all connected

reef ravine
#

you have Serial.begin(115200); so the Serial Monitor needs to be set the same

stone dirge
#

i have the monitor set to "Both NL & CR" at 115200 baud

#

Monitor reads:18:29:09.763 -> ⸮.........
18:29:16.970 -> Adafruit IO connected.
18:29:17.110 -> received <- LOW

reef ravine
#

ok, now send a HIGH (however you are doing that with your IoT provider)

stone dirge
#

but led is not working

reef ravine
#

ok, so my guess about "which pin is which" was probably wrong

stone dirge
#

should i move it around to different pins to check?

reef ravine
#

on these boards you need the pin definitions, as physical pins and GPIO pins may be different

#

see if you can find the pin which toggles with the DVM

stone dirge
#

dvm?

reef ravine
#

Digital Volt Meter

stone dirge
#

so use my voltmeter to check each pin?

#

i really need alligator clips lol

reef ravine
stone dirge
#

mines plugged into pin 3

#

and the code is set for pin 3

reef ravine
#

serial says it's toggling, so the pin specified must be wrong

stone dirge
#

ok let me test each pin

#

that didn't work

reef ravine
stone dirge
#

i tried on and off with all the pins, they all stayed the same

reef ravine
#

I generally use a Wemos D1 Mini, about the same size but more pins are broken out

stone dirge
#

Yeah, i bought this with minimal research.

reef ravine
#

looks like you can use GPIO0 and 2, but they are normally HIGH and your program needs to set them low

stone dirge
#

so, to my understanding if i were to switch to pin 5 it should work?

#

because it pulls from low to high rather than high to low like on pin 3

#

correct me if im wrong

#

or switch HIGH and LOW on the code

reef ravine
#

i'd stick with pin 3 (GPIO2) but change the logic in your sketch to set the pin LOW rather than HIGH

stone dirge
#

ok let me try that

#

if(data->toPinLevel() == HIGH) Serial.println("HIGH"); else Serial.println("LOW");

#

switch all of those correct?

reef ravine
#

looking at it, just reverse the LED circuit, Vcc > LED anode, LED cathode > resistor > pin 3

#

looks like pin 3 will always be HIGH, sending LOW would then turn on the LED

stone dirge
#

ok let me try

#

so can i just flip the led

#

and keep the code the same

reef ravine
#

flip it and tie it to Vcc rather than ground

stone dirge
#

oh i see

#

does it have to be vcc or can it go directly to 3.3v?

reef ravine
#

in this case 3.3v is Vcc

stone dirge
#

OK that makes sense

reef ravine
#

Vcc is a generic term for "positive power supply", could be 3.3v, 5v, 12v, whatever

stone dirge
#

ok, i have a lot to learn lol

#

ive only ever taken 2 physics classes, where we barely touched on circuits and 1 c++ class, which was 10 years ago...

reef ravine
#

i think Mr. Newton was still teaching physics when last I had a class in it lol

stone dirge
#

ok so that didn't seem to work

reef ravine
#

if you measure pin 3 does it ever go low?

stone dirge
#

im getting about 2.3v on pin 3

reef ravine
#

double check that the anode of the LED is going to Vcc, maybe it's backwards

restive pond
#

Yo can anyone help me start out with arduino

stone dirge
#

@reef ravine ah i had the led flipped

reef ravine
#

ok, I have to go, good luck with it!

stone dirge
#

hey thank you so much for the help

#

I really appreciate it

#

i'll just keep messing around with it. have a good one

upper cargo
#

does anyone know other resources for heritage arduino ide -- micr$oft site not offering. win 8.1

north stream
broken summit
#

NeoPixel matrix
Hello is there anyway to rotate the way text scrolls on a matrix i need it to scroll landscape but at the moment its scrolling portrait and i am unsure on how to do this if anyone can help thanks

code https://pastebin.pl/view/ff9286c3

north stream
#

I think the GFX library supports various ways to orient and scroll text

broken summit
#

it think it has but i am unsure on how to use it

north stream
#

Some of the examples should show how to do things like that

obtuse spruce
#

@broken summit - do you want the text rotated, or just the scrolling to be vertical?

#

If you want drawing to be rotated, use this:

  matrix.setRotation(1);

If you want it rotated "the other way", use 3.

#

Just do that one in setup()

broken summit
#

@obtuse spruce thanks this works

jovial heart
#

i am geting this error avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

ivory gorge
#

Hey all, I’ve been using an attiny85-based board similar to this one https://www.adafruit.com/product/1501

It’s great but it doesn’t have a lot of pins and I’m looking for something that has a lot more pins, such as the teensy https://www.adafruit.com/product/4323

Is there something in between? jumping all the way from an attiny85 to a teensy is massive overkill (I don’t need 90% of what the teensy offers) so I’m just trying to figure out if there’s a better option

#

For reference this is what I’m using currently, I have the lipo battery connector and micro USB port desoldered so I can shove it into a much slimmer space https://www.olimex.com/Products/Duino/AVR/OLIMEXINO-85S/open-source-hardware

I feel like this might be a suitable board but it’s out of stock, forgot to mention it https://www.tindie.com/products/femtoduino/femtousb-atmel-arm-cortex-m0/

Tindie

Arduino compatible, Atmel SAM D21 chip, open source!

woven mica
#

@ivory gorge arduino Nano is between those two

ivory gorge
#

Ooh that has an utterly delicious number of pins

#

I went to the dev boards section of Adafruit and started opening all the potential products in new tabs and quickly realized I would have hundreds of tabs whoops

#

@woven mica looks like this is the closest thing from Adafruit? https://www.adafruit.com/product/2590

Or perhaps https://www.adafruit.com/product/2010 ?

woven mica
#

Yes the metro mini is like Nano

elder hare
#

having some trouble with my Matrix here 16x16 where when it display an image, every other line is reversed! (maybe zigzag)? how do i fix this in the code so it display correctly?

elder hare
#

what is the best library to use a Matrix? mine is 16x16 (256) WS2812B 🙂

ivory gorge
#

I don’t have much experience with that but something tells me your library will have an option for row/column vs zigzag

elder hare
#

currently im just using FastLED library

#

i dunno if i have to use like FastLED_NeoMatrix lib or :S

ivory gorge
elder hare
#

never had this error befor, what does it mean?

src\bitmaps/smb.h:41:1: error: narrowing conversion of '4278190080u' from 'unsigned int' to 'long int' inside { } [-Wnarrowing]
north stream
#

It means a variable is being converted from a more precise one to a less precise one

#

In this case, the value is large enough that it can affect the sign bit and cause problems

elder hare
#

how do i fix that exactly? :S

#

a value of type "const long *" cannot be used to initialize an entity of type "const long"

lone ferry
#

The first warning was because you should use const unsigned long. The second warning I guess is from using PROGMEM.

north stream
#

Also, the values given (like 0xff000000) won't fit in a const long

elder hare
#

there is no issues posted either on that github

north stream
#

Either nobody has tried it, they ignored the warnings, they're running a different compiler configuration, or they didn't bother to post issues

elder hare
#

using progmem that means i can't alter the bitmap/image right?

north stream
#

It depends on when/how you want to alter it.

elder hare
#

i have python program running that takes a 16x16 image converts it and then sends it to the ESP32

glossy folio
#

hey, I'm trying to program an esp8266 board (Feather Huzzah!) from ubuntu 19 (linux kernel 5.3.0-63), and I'm having trouble getting the drivers to work, or at least getting it recognized by Arduino. I've been following this tutorial (https://learn.adafruit.com/adafruit-feather-huzzah-esp8266?view=all#using-arduino-ide) and I did the driver installation but it's still not showing up in the Arduino application. Checked with a cable i know supports data transfer, and I got it working on windows, did I do the driver thing wrong? (Also doesn't appear with lsusb)

Adafruit Learning System

WiFi with built-in battery charging for IoT on-the-go!

elder hare
#

so i need to "fix" this

argument of type "long" is incompatible with parameter of type "const long *"
    void drawBitmap(const long* bitmap) {
    FastLED.clear();
    bool LTR = true;
    for (int i = 0; i < NUM_LEDS; i++) {
        if (LTR) {
        for (int j = 0; j < COLS; j++) {
            leds[i + j] = pgm_read_dword(&(bitmap[i + j]));
        }
        } else {
        for (int j = COLS - 1; j > 0; j--) {
            leds[i + COLS - j] = pgm_read_dword(&(bitmap[i + j - 1]));
        }
        }

        i = i + COLS - 1;
        LTR = !LTR;
    }
    }

    void drawAnimation(const long* bitmaps, int s, int delayTime) {
    for (int i = 0; i < s; i++) {
        drawBitmap(bitmaps[i]);                                          // This is the error
        delay(delayTime);
    }
    }
lone ferry
#

Try: const long** bitmaps

elder hare
#

ok that error gone

#

@lone ferry ty

lone ferry
#

What line?

elder hare
#
const long DigDugTaizo[DigDugTaizoSize] = { DigDugTaizo01, DigDugTaizo02 };
const long DigDugTaizoShovel[DigDugTaizoShovelSize] = { DigDugTaizoShovel01, DigDugTaizoShovel02 };
const long DigDugPooka[DigDugPookaSize] = { DigDugPooka01, DigDugPooka02 };
const long DigDugFygar[DigDugFygarSize] = { DigDugFygar01, DigDugFygar02 };

these

lone ferry
#

Pretty sure these should be const long * with the *

north stream
#

Those 32-bit quantities may still cause problems in a signed 32-bit variable.

lone ferry
#

Yes, it should really be const unsigned long *.

elder hare
#

that one gone, ty @lone ferry 🙂

#

now this error

src\bitmaps/galaga.h:41:1: error: narrowing conversion of '4278228887u' from 'unsigned int' to 'long int' inside { } [-Wnarrowing]
#

what was that again?

lone ferry
#

What we just said 😉

elder hare
#

change static const long DigDugTaizo01[] PROGMEM =

to

const unsigned long

#

?

lone ferry
#

Yes, but also with static still in there.

elder hare
#

@lone ferry

lone ferry
#

@elder hare Everywhere it says const long you need to change that to const unsigned long

elder hare
#

that is done :S

lone ferry
#

Still getting that warning?

#

Maybe you also need to put UL behind all those numbers then, as in 0xff000000UL. Weird that the compiler doesn't see 0xff000000 as an unsigned long, though.

#

Easiest way to do this is to copy those lines into a text editor and replace , with UL,. No need to type that all in. 😉

elder hare
#

w00t!!! 😛

lone ferry
elder hare
#

never had that befor 😛

lone ferry
#

It's because the Arduino C++ compiler treats ints as 16-bit numbers, but other C++ compilers use 32-bit numbers.

elder hare
#

aahaa 🙂 im using Visual Studio btw

lone ferry
#

What device are you compiling this for?

elder hare
#

ESP32

lone ferry
#

Hmm, not sure what the sizes of datatypes are for that. But hey, if it works, it works. 😄

elder hare
#

not sure it's working still im converting now

#

@lone ferry the error is still there :S weird

lone ferry
#

Where?

elder hare
#

now it works!

#

now i just need to figure out how to make FastLED use ZigZag as my Matrix im pretty sure is ZigZag (so every other line is reversed)

#

on github it says that FastLED has fixed this and implemented this function into FastLED :S but i can't find it

quartz furnace
#

THis is the demo code

#

It tries to compile and has issue with this part of the code "#error define the pin and wire instance used for your board"

#

Also board is a --> #if defined(ARDUINO_B_L4S5I_IOT01A)" Couldn't find anything helpful on a google search

#

Edit what board is a ARDUINO_B_L4S5I_IOT01A ?

cedar mountain
quartz furnace
#

ahhh good find

#

So just take that part of the code out and define proper pins for GPO. LPD, SDA and SCL?

#

Feather 328P I know how to find SCL/SDA ... any pins to avoid for LPD and GPO?

#

Actaully .. reading the product page a 328P does not have enough specs to run it.. will have to use another board

#

Anyobe able to help with pin assignment ? This is the only M0 I have righ now.. should be fine to use ? I am not doing anything with Wifi just a test of the ST25DV16K

elder hare
#

so this is weird

#

it is correct and 16x16

#

however

#

my ESP32 displays it like this

#

you see the black LED (off)

#

only on the blue side :S

#

and if i flip the matrix / image it follows

#

This is the function that does it, any error in here that might cause this? :S

    void drawBitmap(const unsigned long* bitmap) {
    FastLED.clear();
    bool LTR = true; // Flips the image
    for (int i = 0; i < NUM_LEDS; i++) {
        if (LTR) {
        for (int j = 0; j < COLS; j++) {
            leds[i + j] = pgm_read_dword(&(bitmap[i + j]));
        }
        } else {
        for (int j = COLS - 1; j > 0; j--) {
            leds[i + COLS - j] = pgm_read_dword(&(bitmap[i + j - 1]));
        }
        }

        i = i + COLS - 1;
        LTR = !LTR;
    }
    }
quartz furnace
#

For faster help maybe in the help withCircuit python?

elder hare
#

I need help on the arduino part not the python part

#

The code i pasted is arduino

quartz furnace
#

ahhh, cool wanted to make sure you had quick help

lone ferry
#

@elder hare for (int j = COLS - 1; j > 0; j--) { should be for (int j = COLS - 1; j >= 0; j--) {

#

Probably.

elder hare
#

@lone ferry still black pixels :/

#

at the same place*

#

hmmm

#

@lone ferry when i changed for (int j = 0; j < COLS; j++) { this to for (int j = 0; j <= COLS; j++) { this the black spots became green

obtuse spruce
#

i = i + COLS - 1; is wrong ... should be i = i + COLS;

#

AND

#
            leds[i + COLS - j] = pgm_read_dword(&(bitmap[i + j - 1]));

needs to be

            leds[i + COLS - 1 - j] = pgm_read_dword(&(bitmap[i + j - 1]));
#

ack... wait...

#

fie - hold on, let me give you a clean version of it all at once

#
void drawBitmap(const unsigned long* bitmap) {
    FastLED.clear();
    bool LTR = true; // Flips the image
    for (int i = 0; i < NUM_LEDS; i += COLS) {
        for (int j = 0; j < COLS; j++) {
            int k = LTR ? j : COLS - 1 - j;
            leds[i + k] = pgm_read_dword(&(bitmap[i + j]));
        }
        LTR = !LTR;
    }
}

elder hare
#

@obtuse spruce there we go 🙂

obtuse spruce
#

There - I cleaned up several things:

  • bump i in just one place
  • eliminate the if, because both branches were very nearly the same - removing repeated code makes code easier.
  • introduce k which is the only thing that really changes LTR or !LTR: You either go forward or backward on the leds... the rest is the same
  • used the ?: operator - which forces the code to be clear that the two options are the same kind of thing - we don't want to set an LED in one side of an if and launch kites in the other side - we only want to pick an LED index on either side of the conditional. if lets you do anything on either side, ?: constrains the sides to be consistent.
#

Lastly, this code tried really hard to avoid all the - 1 bits all over the place... they are hard to reason about (I missed several things on my first two attempts to fix the code) - and generally a "code smell" if you have more than one of them in a tight loop like this.

elder hare
#

would you look at that 🙂 ty for that one @obtuse spruce 🙂

obtuse spruce
#

most welcome

quartz furnace
#

Hi mzero are you able to help with an example code written for a STM32 Discovery board: need it to work on a M0 ... need help with pin assignments

obtuse spruce
#

Sure - I can look - which M0 board is it?

quartz furnace
obtuse spruce
#

got it - what the issue / code?

quartz furnace
#

What to assign for // #define GPO_PIN PE4
// #define LPD_PIN PE2
// #define SDA_PIN PB11
// #define SCL_PIN PB10

#

I have no experience using pin names like "PB11" usally just a raw number, I'm sure you have to be careful with Pins that are resets and whatnot

#

And don;t see an exact match for a PE2

obtuse spruce
#

yes, those are uncommon - but in the CMSIS (the files from the chip maker) - PB11 and PB10 are defined as "pin" 43 & 42 -- but I don't think those are Arduino Wiring pins, but instead, actual pins

#

And I can't find PE2 at all --- so I'm assuming that the core header files from the STM32 discovery board defines these -- as Arduino wiring pins. I don't have that core... BUT - it should be easy to find the right values for your Feather M0 board

quartz furnace
#

Looks like PA22 and PA23 for SDA SCL

obtuse spruce
#

first, the following will probably work on any board:

#define SDA_PIN PIN_WIRE_SDA
#define SCL_PIN PIN_WIRE_SCL
quartz furnace
#

ok cool

obtuse spruce
#

those PIN_WIRE_XXX constants are defined to be Arduino Wiring pin numbers --- which each board's core code has tables that map these "pin numbers" to actual pins on the chip - (and ports and bit numbers).

elder hare
#

hmm i can't use pastebin here?

quartz furnace
#

I foundout pins 2,4,7,8 look to be all used by the WINC

obtuse spruce
#

Now - I'm not sure what GPO_PIN and LPD_PIN are used for

elder hare
#

so this is my main.ino
https://pastebin.com/Bwm71aUG

this is the GalagaBoss image array
https://pastebin.com/Fy3gFsvg

why wont it animate :S maybe im missing some small little detail :/

quartz furnace
#

Same.. I know when the borad came out they had a demo. .. wonder if they plan to post it

#

It would be helpful to see a wiring of how they had it hooked up too

north stream
#

Maybe the UPDATE() method isn't getting called?

obtuse spruce
#

OH - those are just generic pins used to initialize that st25dv library - they aren't used in that sketch at all.

elder hare
#

@north stream iforgot myself there xD that was MyFastLEDMatrix.h xD

quartz furnace
#

ohhhh

elder hare
#

this is the main.cpp

#include <Arduino.h>
#include <WiFi.h>
#include "MyFastLEDMatrix.h"
#include "MyWifi.h"
#include "MySocket.h"

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

  WiFi.mode(WIFI_STA);
  WiFi.setSleep(false);

  FastLED.setBrightness(64);

  FastLEDMatrix->SETUP();

  MyWiFi->begin();

  MySocket->begin();
}

void loop() {
  FastLEDMatrix->UPDATE();
  MySocket->loop();
}
#

and yes it gets called

obtuse spruce
#

@quartz furnace - at least I don't think they do.... what are you trying to do? Write to a writable NFC tag?

quartz furnace
#

The demo that was show is you take your phone to this board and you can read it by NFC

#

shown*

north stream
#

You may need to make your update time variable a class member

quartz furnace
#

@obtuse spruce So that leaves it wide open for the pin to use? Just avoid the ones for the WINC chip i.e 2,4,7,8 ?

obtuse spruce
#

Okay - so - Does your feather have NFC on it? I see WiFi... but not NFC?

elder hare
#

@north stream they are now class members and it still doesn't animate :/ erh what could be wrong

quartz furnace
#

@obtuse spruce So I can't use a 328P due to spec limitations.. this is the only M0 borad I have

#

So the thought was to test it on that board, just not load anything to do with WiFi

obtuse spruce
#

@elder hare - it doesn't animage because drawAnimation simply draws a the bitmaps on top of each other each time it is called from UPDATE

elder hare
#

but in the drawBitmap i have FastLED.clear(); that would clear the matrix?

obtuse spruce
#

@quartz furnace - but I don't think there is any NFC hardware on that feather you are using.

#

Is your aim to do something with NFC?

quartz furnace
#

Let me post the board from the site

obtuse spruce
#

@elder hare - is your aim, each time UPDATE is called, and it passes the curtime > lasttime check, that it draw one bitmap from the list, and then the next time, draw a different one, etc....

quartz furnace
#

Seems like it has the NFC in the breakout

elder hare
#

@obtuse spruce ooooh looking at the serial monitor the ESP32 crashes constantly 😐

#

@obtuse spruce yes

obtuse spruce
#

AH - okay, I missed that you have that

quartz furnace
#

no worries..

elder hare
#
Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
[DNS]  DNS Adress : esp32Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d182b  PS      : 0x00060230  A0      : 0x800d68e4  A1      : 0x3ffb1f90  
A2      : 0x00000000  A3      : 0xfbb7cffd  A4      : 0x3ffc1080  A5      : 0x3ffc1e08  
A6      : 0x3ffc1958  A7      : 0x3ffc10e0  A8      : 0x800d182b  A9      : 0x3ffb1f70
A10     : 0x0000007d  A11     : 0xfbb7cffd  A12     : 0x3ffc1e08  A13     : 0x00000005  
A14     : 0x3ffc152c  A15     : 0x3ffc1e08  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x400d182b:0x3ffb1f90 0x400d68e1:0x3ffb1fb0 0x40088b7d:0x3ffb1fd0
#

hmmm :S

#

Core 1 Panic'ed xD

quartz furnace
#

Wish I had a regular M0 or M4 @obtuse spruce ... I know it adds a bt of compexity using one with WiFi

obtuse spruce
#

GOT IT

#

No, the WiFi isn't an issue

#

OKAY

#

So - how have you wired the break out to the board? I'm assuming that SCL and SDA are going to SCL and SDA as marked on the feather, right?

quartz furnace
#

yep

obtuse spruce
#

and where did you wire the GPO pin on the breakout?

quartz furnace
#

Haven't yet.. Got confused by the naming PB11 etc

obtuse spruce
#

gotcha - well, it is just a logic pin that tells you that some device RF'd with the breakout.... so if you sketch doesn't need it - don't wire it. If you do want then, just pick and unused pin that is both digital and interrupt capable.... which is almost all of them!

#

How about 5 - that's not used for anything

quartz furnace
#

cool. okay and the LPD pin? I think that was the name

#

Yeah, LPD has some assignment ... And cool for pin #5 for GPO

obtuse spruce
#

I don't see LPD being used AT ALL in the ST25DV library - other than to provide simple functions that are just calls to digitalWrite and digitalRead

#

It is totally pointless..... So, whoop it up, define it as, er, 0

#

or better yet, 99 or something absurd

elder hare
#

erh what is going on -.- i've disabled almost everything

#

still crashes

obtuse spruce
#

@quartz furnace - and I just searched through the library .... turns out it doesn't use the GPO pin either!!! so, no point in wiring it ... but you can if you intend to build your own things

quartz furnace
#

Cool.. @obtuse spruce I did not know you could use a pin number not on the board

obtuse spruce
#

well - I'm sure the code will do something HORRIBLE if you ever execute code that uses such a pin.

quartz furnace
#

@obtuse spruce ahhh cool.. Wish they would have left more in the 'notes' part of the code

obtuse spruce
#

But - the point is, it isn't going ever get called!

#

Unless you or some example sketch calls a function called ST25DV_GPO_* or ST25DV_LPD_*

#

and really - there is no point in calling those - just use pinMode and digitalRead and digitalWrite yourself - will make things clearer anyway!

quartz furnace
#

@obtuse spruce interesting .. must just need defined to compile

elder hare
#

ok there we go! it's no longer crashing now i just need to find out what is causing the crash

what i did was this

void loop() {
  //FastLEDMatrix->UPDATE();
  MySocket->loop();
}

so something inside the FastLEDMatrix class is causing the crash but i dunno what

obtuse spruce
#

@quartz furnace - yeah, you need to define them to something - any int at all - because the begin call needs them - but all the library does with them is save those two integers away, in case anyone calls those utility functions --- which nothing in the library or example sketches every does!

#

Basically they've got old legacy code in there and they need to clean it or document that it is there for older sketches (I'm guessing)

quartz furnace
#

@obtuse spruce Thanks!

lone ferry
#

@elder hare Your code is trying to read from an illegal address in memory.

north stream
#

There does seem to be an unnecessary pointer in the class for some reason

scarlet imp
#

Hi all. I wondering if anyone has ssl (client) working on ethernet ( not wifi ), on a adafruit feather. I'm using the m4 express, I tried modifying the ArduinoBearSLL WIFIsslClient example, which led to trying to get the ECCX08 random number generator example working ( the library is needed for BearSSL ), which led to maybe I need to define the wire that the crypto chip on the M4 uses, and then I got lost in the rabbit hole. Docs say the feather has a crypto chip on it, but no more details. I just want to connect to https. 😕

elder hare
#

@lone ferry hmmm :S

lone ferry
#

@elder hare If you comment out the for loop in drawAnimation, and just do drawBitmap(bitmaps[0]); it will probably no longer crash.

elder hare
lone ferry
#

But it does draw something?

#

I don't know if I have all your code but it does seem like you never actually create the FastLEDMatrix instance anywhere.

elder hare
#

no now it does not draw anything as i have commented out this part in UPDATE()

        // Check Strip Array Current Pattern and switch accordingly
       /* switch (1){
          case 1: drawAnimation(GalagaBoss, GalagaBossSize); break;
          case 2: break;
          case 3: break;
          case 4: break;
          default: break;
        }*/
lone ferry
#

But before you commented that out, it did draw something?

elder hare
#

weirdly yes :S the moment it starts up it starts crashing but it displays an image on the matrix

lone ferry
#

Where is the line in your code that does FastLEDMatrix = new MyFastLEDMatrix();?

elder hare
#

all i have is this at the bottom of the pastebin i linked you

MyFastLEDMatrix *FastLEDMatrix;
lone ferry
#

Well, add the line FastLEDMatrix = new MyFastLEDMatrix(); to setup(), above the call to FastLEDMatrix->SETUP();

elder hare
#

'FastLEDMatrix' was not declared in this scope

lone ferry
#

That makes no sense. Maybe you should put the latest versions of all your code files somewhere.

elder hare
#

huh?

lone ferry
#

I can't really give you good advice if I don't know exactly what your code looks like.

elder hare
lone ferry
#

yup

#

The problem is that you call FastLEDMatrix->UPDATE() but the variable FastLEDMatrix has some random value in it.

#

So you need to write FastLEDMatrix = new MyFastLEDMatrix(); first, in your setup().

elder hare
#

aaaand that fixed it :S

#

weird that it worke this time :S

#

i feel the error stuff in Visual Studio is weird :S

lone ferry
#

Well, you need to do everything exactly right in C++ or it won't work. 😉

elder hare
#

okey now that it does not crash! the image is still not animating

lone ferry
#

But it does show an image, right?

elder hare
#

yupp 🙂

lone ferry
#

You need to put some kind of delay in the for-loop that does the animation or it will go way too fast.

elder hare
#

hmm still nothing :S

lone ferry
#

How big is your delay?

elder hare
#

500

lone ferry
#

Where did you put it?

elder hare
#
    void drawAnimation(const unsigned long** bitmaps, int s) {
      for (int i = 0; i < s; i++) {
        drawBitmap(bitmaps[i]);
        delay(500);
      }
    }
lone ferry
#

I guess you need to put a FastLED.show(); right after that delay.

#

Anyway, GTG. Good luck 🙂

elder hare
#

okey it worked now

#

but sad that i have to use delay() :S

#

@north stream why MUST i have delay? why can't i use the millis? :S

north stream
#

You can use millis unless something is interfering with the timer/interrupt

elder hare
#

it should work as this

  #ifndef MYFASTLEDMATRIX_H
  #define MYFASTLEDMATRIX_H

  #define FASTLED_INTERNAL
  
  #include <FastLED.h>
  #include <pgmspace.h>
  #include "bitmaps/digdug.h"
  #include "bitmaps/frogger.h"
  #include "bitmaps/galaga.h"
  #include "bitmaps/pacman.h"
  #include "bitmaps/smb.h"
  #include "bitmaps/qbert.h"

  #define LED_TYPE WS2812B
  #define DATA_PIN 23
  #define COLOR_ORDER GRB
  #define NUM_LEDS 256
  #define COLS 16
  #define BRIGHTNESS 16

  CRGB leds[NUM_LEDS];

//====================================================================================================================== //
// CLASS - MY FASTLED MATRIX
//====================================================================================================================== //  
  class MyFastLEDMatrix {

    public:

    unsigned long lastUpdate = 0;
    int Delay = 255;

    void drawBitmap(const unsigned long* bitmap) {
        FastLED.clear();
        bool LTR = true; // Flips the image
        for (int i = 0; i < NUM_LEDS; i += COLS) {
            for (int j = 0; j < COLS; j++) {
                int k = LTR ? j : COLS - 1 - j;
                leds[i + k] = pgm_read_dword(&(bitmap[i + j]));
            }
            LTR = !LTR;
        }
    }

    void drawAnimation(const unsigned long** bitmaps, int s) {
      for (int i = 0; i < s; i++) {
        drawBitmap(bitmaps[i]);
        FastLED.show();
      }
    }

    void UPDATE() {    
      unsigned long curtime = millis();
        
      if (curtime > lastUpdate) { lastUpdate = curtime + Delay;
           
       switch (1){
          case 1: drawAnimation(SMBMario, SMBMarioSize); break;
          case 2: break;
          case 3: break;
          case 4: break;
          default: break;
        }
             
      FastLED.show();
      }
    }
    
  };

  MyFastLEDMatrix *FastLEDMatrix;

  #endif
#

@north stream right?

north stream
#

As both matthijs and I pointed out, that declaration isn't correct.

elder hare
#

what declaration?

north stream
#
MyFastLEDMatrix *FastLEDMatrix;
elder hare
#

i have this in setup aswell

FastLEDMatrix = new MyFastLEDMatrix();
north stream
#

Then you can delete the other one.

#

You'll still need a declaration somewhere, I suppose.

elder hare
#

yea cause if i delete the other i get

identifier "FastLEDMatrix" is undefined
#

how what when?

obtuse spruce
#

So - a common way to deal with singleton classes is just statically declare one. So long as you don't use anything "complex" in the constructor, you're fine, and in generally it makes things much easier.

In this case, just do this in the header file:

Class MyFastLEDMatrix {
  ...
};

and in the .ino file, the one place where it is used, do this:

MyFastLEDMatrix theMatrix;
...
void loop() {
  ...
  theMatrix.UPDATE();
}
#

If you want to use theMatrix from multiple different code files... that is possible also:

In the .h file do this:

...
extern MyFastLEDMatrix theMatrix;

Then create a MyFastLEDMatrix.cpp file that has:

#include "MyFastLEDMatrix.h"

MyFastLEDMatrix theMatrix;

And lastly, in each file that needs to use theMatrix:

#include "MyFastLEDMatrix.h"
...
void someFunction() {
  ...
  theMatrix.SomeFunction();
  ...
}
hard forge
#

Hi all, I'm looking for help implementing the Arduino BLE library to create a peripheral device that multiple centrals can read from. I've covered my bike in NeoPixels with Arduino Nano 33 IOTs in each of the wheels, and a third Nano 33 IOT on the bike frame switching between animation modes with a NumberPad controller. I thought I would be able to make the nano on a Peripheral and "serve" the mode to the other two nanos in the wheels.

#

My questions are:

#
  1. Is this possible?
#
  1. Is there a better way using different hardware?
#
  1. Do you know of an example of how to set this up?
obtuse spruce
#

I don't know any particulars about doing BLE on an Arduino, but in the face of it, it seems unlikely that a single device can server multiple centrals easily. Why not do it the other way around, having the spokes be the peripherals to the frame as central?

hard forge
#

Thanks! I did try the other way around, and I've been able to send the "mode" from the central to the peripheral, but I don't know how to connect a second peripheral at the same time. 🤔

#

So the root of my question is: Does anyone know how (or know of an example or project) to use BLE to share a piece of data wirelessly between 3 Arduino's?

ivory gorge
#

I’ve only ever seen Lora used for that tbh, I can’t say I have experience with ble hardware like that. That said, how much latency can you put up with?

#

Might it be possible to switch between modes to keep them all communicating with each other

hard forge
#

For now, I'd take a few seconds lag if I could get it to work. 🙂

ivory gorge
#

Aight

#

If it’s possible to get the devices to flipflop between central and peripheral modes I would consider that as a workaround unless you’re trying to do like, synced animations

hard forge
#

That's interesting. Like daisy chaining the communication rather than broadcasting.

ivory gorge
#

Oh

#

They have WiFi

#

Why use Bluetooth if you can use WiFi for that? Curious

hard forge
#

Honestly, I started the project wanting to learn more about BLE- but now I'm SO OVER that- haha. I didn't think of Wifi - I assume they can create their own network?

stone dirge
#

Can anyone help me out with my esp8266-01? I am trying to control a LED through adafruit IO. I am using the adafruit digital_out example code and the device is connected and receiving data, but the LED is not responding.

15:48:30.748 -> Adafruit IO connected. 15:48:30.889 -> received <- LOW 15:48:32.505 -> received <- HIGH 15:48:34.454 -> received <- LOW 15:57:55.157 -> received <- HIGH 15:57:58.310 -> received <- LOW

#

I have pin 3 (GPIO 0) active in the code and the LED is connected to pin 3

ivory gorge
#

They use a different chipset than I’m used to so they might not offer the ability to create an AP, but if they can you could do it that way, or potentially set up a WiFi direct / ad hoc group

#

That said, the webpage says they can be both ble host and client, so hmmmmmm

hard forge
#

Right that's why I was excited about the nano IOT - I had originally wanted to go with Adafruit Feathers but they didn't have the ability to be a "Peripheral / Server" and I didn't want to have to use my phone as a controller. It's an interesting thought tho - to create a wifi network between them instead. I'll look into that and maybe I'll leave my learning about BLE to another project. 🙂

ivory gorge
#

Aye, wish I could be of more assistance, I’ve mostly stuck to the wired things :)

hard forge
#

Thanks for your help! Me too... wires are so ... trustworthy. 😎

ivory gorge
#

They just don’t do well when you wrap them around bike wheels and go for a ride, that’s for sure!

hard forge
#

Haha no...

ivory gorge
#

Oh wait

#

You don’t have three 33s?

#

You have a 33 and two feathers?

#

Your 33 needs to be set up as the peripheral

#

The feather wings will be the centrals

hard forge
#

Right now all 3 are Arduino Nano 33 IOTs

ivory gorge
#

Ah, ok

hard forge
#

Yeah I

ivory gorge
#

I glanced at the project link you posted and it said you had the feather wings in the wheels

hard forge
#

ve been reading that document over and over for weeks haha

#

Oh! That was the original plan. And then I started to learn 2 different BLE libraries and my brain started to explode :p

#

But switching to the Nanos didn't make it much better haha

ivory gorge
#

There’s a lot of links on the right side of that page for how to use the code, with lots of examples; the document gives an overview of how things work and the code should help clarify?

hard forge
#

Right, unfortunately, I'm learning as I go, and the examples say what to do but not why and when, so I've struggled with it. My best try code is listed at the bottom of my blog post (although it's a bit long because it includes the neopixel animations too)

ivory gorge
#

Fair enough!

#

This looks like it has lots of good example code as well

#

If I had the ble version of the iot nano I would do some testing for you but I have the Lora versions >_>

hard forge
#

I dont' know Lora - should I look into it for this project?

ivory gorge
#

Your current devices should work alright, to be honest

#

Lora is for long range / low [data] rate, so trying to stream audio reactive animations in real-time over Lora is gonna give you more headaches than doing it with ble

hard forge
#

Gotcha. Yes I just need to send data a few feet. Thanks for the help 🙂

north stream
#

I might split the difference and use ordinary RFM69 type radios and the RadioHead library (BLE has its own headaches)

#

Or for just a few feet, your original WiFi idea might be the right one

hard forge
#

Ah... I was just reading about that yesterday. Something seemed out of date tho - was it discontinued?

north stream
#

The RFM69 chips or the library?

hard forge
#

The library

ivory gorge
hard forge
#

Oh wow that looks very helpful. Thank you!

north stream
#

Even if Mike McCauley's original RadioHead library isn't maintained (I hadn't heard anything), Paul Stroffregen (of PJRC/Teensy fame) has a fork of it, and SparkFun has their own fork as well.

#

It's a pretty solid and expansive library, even if no one else were maintaining it, I'd probably keep using it, as it serves my purposes nicely.

hard forge
#

Ok thanks! I'll look into it. At this point any radio communication to the wheels that works will be AMAZING. Thank you!

reef ravine
#

still no luck @stone dirge ?

clear fog
#

afternoon! I was wondering if its possible to count the number of Bluetooth devices I have passed using a GEMMA M0 and log it to a string

#

I know my question is broad but I'm hoping to be point in the right direction with this idea 🙂

stuck coral
#

It is if you have a bluetooth chipset that can return advertisments which is basically all of them

#

but remember peoples MACs change constantly, so its not terribly great for tracking if that was a goal

clear fog
#

the basic idea is if I go into town for the day, I wanted to get a rough number of people I passed

#

Don't need to be able to track the devices again in the future

stuck coral
#

You could probably graph a rough relative measurement, youll stumble on many many devices around you that have bluetooth but are not a cell phone

clear fog
#

is there anyway to filter them out?

stuck coral
#

Its possible phones typically have a part of their advertisment different, Im not too sure if they set their advertising payload for some extra function you could base the scanner off of

#

I think itll probably just be a list of random MACs is all you get

clear fog
#

I see

#

well that is a start

#

any good resources on writing code to do this kind of thing?

stuck coral
#

Most of the time its specific to the BT chipset, make sure you dont get one of those popular BT Serial modules. Not really sure of a solid recommendation for an external chipset that is good with arduino

clear fog
#

I have a bluno beetle, what about that?

stuck coral
#

Hm maybe, it uses serial like the modules but now that I think of it a part of BLE 4.0 GATT should be its required to return you the advertisment data so you'd have to check the AT commands for that device

clear fog
#

@stuck coral thanks for the info, does adafruit have a board that would be best for this?

#

I like using Adafruit stuff as it has very good documentation

stuck coral
#

I love the nRF52 and they have a few boards if I remember right

#

That will certainly do the job, I just havnt used the Arduino framework with it

clear fog
#

those are big though right?

stuck coral
#

I mean, I think they have a feather with a nRF52 on it, but the nRF52 itself can be quite tiny

clear fog
#

thanks, I'll check it out

#

@stuck coral What is wrong with BT Serial modules like the HC-05 and HC-06

#

you said not to use them

#

@stuck coral Do all smartphones send out advertisements? as long as bluetooth is on?

stuck coral
#

They tend to be limited from what I see, but they might have an AT command to get the advertising data.

#

And yeah, pretty sure they always send advertisments but I could be mistaken, i see when my neighbors get home if I have my scanner open

clear fog
#

Thanks! I would really appreciate that. 😄

neat kayak
#

hey im completely lost when it comes to batteries. If I wanted to power an arduino nano and a 12v water pump with a battery, what battery should I go with for it to last a while. I was thinking something like this https://www.banggood.com/12V-8-x-AA-Battery-Clip-Slot-Holder-Stack-Box-Case-6-Inch-Leads-Wire-p-80721.html?cur_warehouse=CN&rmmds=search and then using a 12v to 5v step down to power the arduino. I have no idea if this would work cuz I have never used batteries before. Any help would be greatly appreciated.

ivory gorge
#

Pumps draw a lot of power, define “last awhile”

neat kayak
#

I want it to last a few days, but I am only turning on the pump for less than 2 seconds at a time every so often

#

its more of a mist sprayer than a continuous water pump

ivory gorge
#

On for a second and off for a second? Off for an hour?

#

You might be better off buying some actual 6v or 12v batteries

#

Instead of AAs

neat kayak
#

it would be on for a second then off for something like an hour. I would prefer for the batteries to be replicable in something like this battery pack if possible

#

or i guess rechargeable would work too

#

would something like this work better?

vivid rock
#

I would certainly use 8 cell NiMH rechargeable or 3cell LiPo (nominal voltage 11.1v) instead of AA.

#

And you do not need a voltage converter - nano has one on board. Typically you can power nano using up to 20 v

neat kayak
#

oh great

#

i guess ill go with the 8 cell nimh and see how it goes

#

thanks for all the help 🙂

vivid rock
#

Of course there are many different nano boards - double-check the specs for yours

neat kayak
#

yea i will for sure

storm harness
#

Is there a way i can multiply two integers as if they were floats in the range 0-1. For example 65535 * 32767 = 32767

#

platform is teensy 4

lone ferry
#

Yes, but you need to do this in 32-bit and divide by 65535 afterwards. (Or rather, shift right by 16.)

elder hare
#

@obtuse spruce i just did what you told me yesterday

#

im still getting weird errors :S

#

even tho i have this function

    void drawAnimation(const unsigned long** bitmaps, int s) {
      for (int i = 0; i < s; i++) {
        drawBitmap(bitmaps[i]);
        FastLED.show();
      }
    }

inside the main UPDATE() function that runs in the main loop

    void UPDATE() {    
      unsigned long curtime = millis();
        
      if (curtime > lastUpdate) { lastUpdate = curtime + Delay;
           
       switch (1){
          case 1: drawAnimation(SMBMario, SMBMarioSize); break;
          case 2: break;
          case 3: break;
          case 4: break;
          default: break;
        }
             
      FastLED.show();
      }
    }

as with the original code you had to have a delay() inside the drawAnimation for loop to make it animate to make it work if not it would just stand still so i figure the problem is in

    void drawAnimation(const unsigned long** bitmaps, int s) {
      for (int i = 0; i < s; i++) {
        drawBitmap(bitmaps[i]);
        FastLED.show();
      }
    }

in the for loop! even tho i have the millis in place the for loop just rams through the "animation" so fast that you dont see it

#

am i wrong?

lone ferry
#

What is wrong is that your drawAnimation tries to run the entire animation, but it should only show the next frame of the animation. The next time it is called, it should show the frame after that, and so on.

elder hare
#

question, how would i solve this? WITHOUT using delay()! need millis

lone ferry
#

drawAnimation(SMBMario, SMBMarioSize, step); where step is a global variable that you update.

#
    void drawAnimation(const unsigned long** bitmaps, int size) {
      drawBitmap(bitmaps[step]);
      step += 1;
      if (step >= size) { step = 0; }
    }
#

Actually I didn't use step as a parameter there, it should be a global.

#

Put int step = 0; somewhere outside your functions.

elder hare
#

i did hmm

#

on this

drawAnimation(SMBMario, SMBMarioSize, step); 

i get

too many arguments in function call
lone ferry
#

Yeah I changed my mind about that one, you don't need it.

safe halo
#

I have a c++ uint8_t *payload
that I am trying to iterate thru by using a

      char license[20];
      for (size_t i = 1; i < (sizeof(payload) + 1); i++)
      {
        Serial_Debug.println((char)payload[i]);
        license[i] = (char)payload[i];
      }
      Serial_Debug.println(license);

but no matter how long the array is it always comes back as 4...
the Payload in this instance is "SWDFE"
In the Serial Monitor it receives the data but I cant get past a count of 4

@SWDFE
S
W
D
F
#SWDF␌␆
lone ferry
#

You can't use sizeof() to get the size of an array like that.

safe halo
#

You can't use sizeof() to get the size of an array like that.
@lone ferry It always comes back as 4

lone ferry
#

C arrays don't actually store their size anywhere.

#

What you're getting here is the size of the pointer, which is 4 bytes.

north stream
#

You can usefully call sizeof() on a fixed array, but not a pointer like that.