#help-with-arduino
1 messages · Page 79 of 1
@north stream hmm i uploaded a simple wifi sketch and well... now it seems STUCK
Connecting to Altibox625721
................ still trying to connect
................ still trying to connect
................ still trying to connect
................ still trying to connect
.....
:S
Looks like a step backwards if WiFi was working previously 😦
yea :/
if i follow the via i can see that it is connected to EN pin on the ESP32
so it was connected / touching the reset button on the one end and the other was soldered to the via
sketch
#include "WiFi.h"
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin("SSID", "PASSWORD HERE");
Serial.print("Connecting to "); Serial.println("Altibox625721");
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(500);
if ((++i % 16) == 0)
{
Serial.println(F(" still trying to connect"));
}
}
Serial.print(F("Connected. My IP address is: "));
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
}
Maybe print out what the WiFi status is, while it isn't connected yet?
Also check to see if you can scan wi-fi, that doesn't require a connection, but will tell you if wi-fi is functional
You can also set up an event handler WiFi.onEvent(WiFiEvent); to catch (and print) any events (and error codes) related to wi-fi
I got 2 LED's, one has VIN 12V and one has DIN 5V, whats the difference between VIN and DIN and can I plug either of them into D4
I was orignally going to control them with ESP8266 but i ordered wrong voltage one
and the one I see on amazon now has a D4 connector, not DIN
so I wana make sure my DIN on LED's will be able to work with D4
please tag me if u reply
DIN is normally "data in". The ESP8266 is a 3.3V module, so you'd need a level shifter to drive a 5V DIN from it.
@north stream Your description about the keyboard emulation for USB -> UART was right, but I'm converting it back to USB. The Teensy converts UART to keyboard instructions, another device converts keyboard to UART and sends it to the Teensy. Like this https://raw.githubusercontent.com/Flowm/etherkey/master/doc/teensy-pi_bb.png
What I'm trying to do is use an arduino micro in place of the teensy here
Actually it's just a serial connection into the teensy and then keys are sent, I didn't quite understand it fully
Hello I am having a problem with a non-arduino device but it is programmed using arduino software, can I ask about it here?
@winter mason sure
I have an esp8266-01S which I am trying to program using the arduino ide, I can upload sketch’s and flash firmware but no matter what I try, any sketch, any baud rate I cannot get the device to respond in the serial monitor
@winter mason you can't get anything to print in the serial monitor or are you trying to type into the serial monitor and get a response.
?
I am not getting any response in the serial monitor
what do you mean by response ?
does your program listen for input from the serial port ?
Yes
have you matched the baud rate in the serial port with the baud rate used in the program ?
what speed is used in the Serial.begin line of your program ?
9600
A problem that I am getting though it doesn’t like the line ESPserial.begin(9600) and any other line starting with espserial
Does Serial.begin(9600); work ? I"ve never seen ESPserial.begin before.
The program I am using uses both espserial.begin and serial.begin, espserial gives an error so I removed the line I get these problems with the serial monitor
The serial monitor in arduino works on the Hardware serial connection. That example you have uses ESPserial as a softwareserial port. Post your code in three backticks like this code here
back tick is the symbol underneath the ~
`
``` code here ```
`#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup() {
Serial.begin(9600);
ESPserial.begin(9600); //errors
Serial.println("");
}
void loop() {
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}`
ok, so why are you using two serials then ? If you want the chip to echo what you type back to you in the same serial window then use the same Serial object like this :
i removed the espserial.begin line
if ( Serial.available() ) { Serial.write( Serial.read() ); }
still not working
if I unplug and plug in with the serial monitor open i get a backwards question mark (⸮)
i can get it to say the "ready" message when it boots up but it still doesnt respond to commands
now i am getting errors
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
@woven wedge I didn't fully understand it either (hence my questions). Did you get it working?
Hey guys, is it possible to trigger an interrupt on falling edge of pwm output?
im measuring a thermocouple thats in series with a heater so i have to either measure when it's not on or turn it off while measuring
(the thermocouple is amplified if thats relevant)
It may be possible to do so via a timer interrupt. Alternatively, connect the PWM pin to an interrupt pin and configure that pin to interrupt on a falling edge.
yeah i thought of that too but i thought maybe timer interrupt would work better?
That's why I suggested the timer interrupt first, as it doesn't require an extra pin and wiring.
what MCU are you using, @pine bramble ? if it is SAMD21 or 51, then you can definitely interrupt on negative edge of the PWM directly in the chip.
atmega328p aka arduino uno
@distant condor - code isn't like wiring - digitalWrite(LED_BUILTIN, state); doesn't connect state to the pin, but only writes the value exactly once when the line of code is executed.
Changing state somewhere else won't immediately change the pin..... Only when a call to digitalWrite is made again. So you need to arrange to call it each time you change state:
void blink()
{
state = !state;
digitalWrite(LED_BUILT, state);
}
Now - you also need to arrange to call blink() again and again....
Fortunately, we have loop().... now loop() is "special" in that it (and only it) is called again and again and again, forever, after startup() is called at the start.
(Note: only these two functions are "special" this way. Other functions you write are only called, if you call them.)
yup understood i just imagined that whenever interrupt changes state it calls blink changing state and on the next ineration of the loop the led changes
So... you might be tempted to write:
void loop() {
blink();
}
...which will call blink repeatedly... but it will be too fast!
Nothing in your sketch's code connects blink to an interrupt.
whoops
missed that line
yeah lol made me question my life choices
sorry - seems like such a common mistake I see here: people call an output function once and expect the variable to bound to the pin forever!
OKAY - so - hrm....
so you see the Serial write output showing pin 2 changing?
do you need to pinMode(2, INPUT) perhaps - (possibly with pull up?)
yup
oh well that could be it but in the long run i plan to attach pin 2 to a encoder
also - just double checking - are you sure pin 2 is interrupt capabale on your particular board?
well i actually didnt know that mzero though all pins were capable of interrupts
its a arduino uno
well it seems that it is capable
in the docuentation
yup - just checked, too
made those pinmode changes but it seems to be the same
led stick to low if thats initiated or high if thats initiated
but in serial monitor i can see th epin 2 changing values
just found out change in pin 2 doesnt even call the fucntion blink
(side note: if you include code blocks rather than images, it will be a bit easier to read... I keep having to zoom my page to read your code!)
whats the html or disco tag for including code blocks? sorry noob here
no prob: three backticks (`) and "C++" then code on the following lines -- and end with a line of just three backticks
int pin = 2;
volatile byte state = LOW;
void setup()
{
Serial.begin(57600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT);
attachInterrupt(2, blink, CHANGE);
}
void loop()
{
digitalWrite(LED_BUILTIN, state);
}
void blink()
{
state = !state;
Serial.println(state);
}```
got it sorry for spam
I don't think you can Serial.println from within an interrupt routine.
oh ok
BUT - try this: set state = LOW at top... Then state = HIGH; inside blink()
This will test if it is ever called. As you have it --- were it to be called twice in a row quickly - you'd never see it
And - since I don't know what it causing 2 to change - perhaps that is possible. Because you set CHANGE - every trigger (button press?) will cause 2 interrupts.
i am just plugging the wire from pin2 to 5v or gnd to test
note that this typically generates multiple interrupts
as the voltage jumps up and down before settling on a new value; google "button debouncing"
but indeed, as @obtuse spruce suggested, first thing to check would be to verify if blink() ever gets called at all
I just checked and blink doesnt get called
also i set the pin 2 to INPUT_PULLUP yet the value remains zero in the monitor
int pin = 2;
volatile byte state = LOW;
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT_PULLUP);
attachInterrupt(pin, blink, LOW);
}
void loop()
{
digitalWrite(LED_BUILTIN, state);
Serial.println(state);
}
void blink()
{
state = !state;
}```
the value of 2 is continously GND never even gets pulled up
Change state to an int type
i found something
Most examples for setting state use int type
digitalPinToInterrupt(pin).....is required instead of just pin
and it seems to be working now kinda
got it working guys with this code ```c++
int pin = 2;
volatile byte state = LOW;
void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT);
attachInterrupt(digitalPinToInterrupt(pin), blink, CHANGE);
}
void loop()
{
digitalWrite(LED_BUILTIN, state);
Serial.println(digitalRead(pin));
}
void blink()
{
state = !state;
}```
also i found soemthing interesting if you put NULL in place of ISR like so c++ attachInterrupt(digitalPinToInterrupt(pin), NULL, CHANGE); a digital read on the pin in question gives garbage values like hexadecimal and other binary stuff
if used correctly as in the code that worked it only gives the desired 0 or 1
also a digital pin constantly oscillates between 0 and 1 if not connected to any output....
good find on both counts, @distant condor
thanks you guys for all the help good luck coding @obtuse spruce @gilded swift
Hey all
I have an Arduino Pro Micro, a 9v batter+harness, a DC motor, and a vibration sensor. Being it's my first day dealing with electronics like this, I was wondering if you can help me wire these together such that when the sensor is closed, the motor spins.
My main question is power, right now. How do I get maximum voltage to the motor while maintaining 5v or so to the sensor?
If these questions don't make sense, please help m correct myself.
Generally you'd want to use USB power for the Micro, since it wants to run on 5V, and can tap into that using the "RAW" pin to power the sensor too. You can wire the motor separately with the 9V if you want to maximize the voltage there, just connecting the grounds. However, you'll need something to control the motor with, like a relay or a transistor, since the Micro can't turn high-current devices like the motor off and on by itself.
Very helpful, thanks!
What would a relay or transistor look like?
Or, is there a better microcontroller for me? Size is a big factor.
I'm googling it now, fyi
Note: motor direction is not important, nor is speed control.
Any microcontroller would generally have the same issue with motors. A basic motor controller might be something like https://www.adafruit.com/product/3190
Gotcha
If you're just getting started, it's a good idea to follow an established tutorial rather than necessarily improvise, as there are a lot of unexpected subtleties in electronics sometimes. 😁
I hear you. I've been doing a lot of piecemeal research and I feel like my needs are quite specific. It's hard to find a tutorial that does what I need, you know?
But to be fair, my needs could be considered very general to you. I'm too new to even tell.
Based on an article I just read, a transistor seems like it'd be a better option?
It would work and be pretty cheap, yep. Picking a particular transistor can be tricky sometimes, though.
"In this lesson, you will learn how to control a small DC motor using an Arduino and a transistor."
https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors
your in luck, @raven wing - that tutorial uses.... a PN2222!
I finally managed to (kind of) get my esp-01 board to work
i found a working sketch that would make the led blink, i modified it to work with serial commands, the current code is
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
delay(250); // Wait for one-quarter of second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
delay(250); // Wait for one-quarter of second
if ( Serial.available() ) { Serial.write( Serial.read() ); }
}```
it will only echo what i type, what would i program to be able to use the AT commands?
You need to burn AT firmware to use the AT commands
i flashed the AT firmware and now i get an error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException every time i type in serial monitor
Perhaps the serial port changed?
Am I stuck with the arduino IDE or can I run and compile from something like VSCode?
There are other options like Keil, gcc, and Atmel Studio. I think VSCode is more of an IDE than a build system, but I'm not sure.
Ty gonna look into those options
@low sundial - there is also https://platformio.org/ - which will integrate with VSCode
My code just does not work(the buzzer does not buzz and led does not shine) void setup() {
// put your setup code here, to run once:
}
int trigpin = 4;
int echopin = 2;
int led = 11;
int buzzer = 13;
void loop() {
tone(buzzer,600);
analogWrite(led,4);
delay(1000);
noTone(buzzer);
analogWrite(led,0);
}
just this part
any fixes?
Thanks
okay
umm was that a answer to this My code just does not work(the buzzer does not buzz and led does not shine) void setup() {
// put your setup code here, to run once:
}
int trigpin = 4;
int echopin = 2;
int led = 11;
int buzzer = 13;
void loop() {
tone(buzzer,600);
analogWrite(led,4);
delay(1000);
noTone(buzzer);
analogWrite(led,0);
}
just this part
any fixes?
Thanks
@blissful meadow what board are you using? (and the answer before related to formatting your code so it reads easier in discord)
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Use of the tone() function will interfere with PWM output on pins 3 and 11
if you leave the PWM out of it does the buzzer buzz?
what is PWM
the analogWrite(led, 4); sets the Pulse Width Modulation on pin 11 to a value of 4 (out of 256)
oh
give me a second
let me set up my project
nope with out analogWrite(led, 4); it does not buzz
void setup() {
// put your setup code here, to run once:
}
int trigpin = 4;
int echopin = 2;
int led = 11;
int buzzer = 13;
void loop() {
tone(buzzer,600);
delay(1000);
noTone(buzzer);
}
thats what i have
to make it easier to read format it with "backtics"
int trigpin = 4;
int echopin = 2;
int led = 11;
int buzzer = 13;
void setup() {
// put your setup code here, to run once:
}
void loop() {
tone(buzzer,600);
delay(1000);
noTone(buzzer);
}```
pin 13 is connected to the onboard LED
is it an UNO R3?
Ya
there is an LED connected to pin 13
But then why is there a pin for pin 13?
mine is old
I change it to pin 8
the buzzer
try
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
}```
okay
you should see an LED blink
sorry, add another delay after digitalWrite(13, LOW);
ok, that is the basic "Blink" sketch found in "Examples"
so until you gain some experience try to avoid using pin 13
you'll get used to it 🙂
but how will My buzzer work?
try rewriting your code to blink an LED on pin 8
brb (dogs need a walk)
Pin 8 does not support PWM, use 9 instead. (It'll blink on 8, but PWM allows you to "dim" the brightness.)
is it wired in the correct polarity?
try flipping it
long one to the common ground
and you have a current limiting resistor in series?
you must use a resistor in series with LEDs to prevent damage
what value?
some value between 220 and 470 will work
I will try to run it with out a resister
don't
nope still no light
my freind does not have a resister and he uses leds
friend*
it burn out in a hour of use
on 5 votl
without them too much current will pass, it'll eventually destroy the LED or worse, the pin
usually the blue bus is used for ground and the red one for +5v
the bus on the breadboard
what do you mean by bus?
and yes you'll thank yourself if you use color coded wiring as much as possible
the long "rails" on either side of the breadboard, they are blue and red
the electrons don't care but I always wire ground to blue, +5v to red
lol, a cool and relevant project
@blissful meadow sorry for such a terse reply, I was gonna post more but something came up IRL
for now try something simple, https://create.arduino.cc/projecthub/karmette/basic-led-setup-for-beginners-0a124a
your resistor is fine for this
I have built a alarm clock that slaps you if you don't wake up
but i haven't used leds
yet
but i will do that
i need an alarm like that - but I wouldn't use it 🙂
and if you flip the leads?
you OK?
step 1: Deenergize taser
so you have pin 8 to resistor to LED to ground?
do you have a multimeter?
it's hard to see in the picture, what are the colors on the resistor?
blue
each stripe
blue,red,blue red,red
in that order?
ya
OK, it say it has 120 resistors
different strips should have different colored bands on them
i have red red blue blue red
anything without blue?
no
tough without a multimeter...
they range from $5US to "how much money you got?" 🙂
resistors are used in every electronic device
they limit the flow of current in a circuit
I mean for Arduino
you'll also use them in motor drivers, MOSFETs, transistors
ah
anytime you deal with the real world as opposed to the micros logic world
by choosing the right value you limit the current that you need
i think your resistor is so large it limits current through the LED to much
lol
but what about my buzzer
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
int buzzer = 5;
int led = 8;
}
int led = 8;
int buzzer = 5;
void loop() {
digitalWrite(13, HIGH);
digitalWrite(led, HIGH);
tone(buzzer,450);
delay(100);
digitalWrite(13, LOW);
digitalWrite(led, LOW);
noTone(buzzer);
delay(100);
}
no specs on it either eh?
well it is a active buzzer
ok, so it has polarity as well
don't worry - after you have years of experience - it'll still happen to you 🙂
i wouldn't depend on "long side" "short side", always best to check markings on body or test
do you have a soldering iron?
ya
not to good
and cheap bangood solder
and soilering iron
that in bad shape
a precise pair of needle nose pliers and a good wire cutter
when you make projects you'll often need to wire things, they help to shape parts to fit
I'm gonna drop a hot take and say I think that solid core wire cut to length is better than jumpers. You can get kits of precut if you don't want to deal with cutting it yourself
I have 23131 jumpers
for breadboarding yes
idk why
(I have my PIR pumpkin in mind 🙂 )
not hard if you have the 8x8 matrix LEDs
mine has a sensor so when the kids walk up it opens its eyes and does effects like that
you can always just flicker led eyes with 2 LEDs
oh ya
or create a cyclops eye on the LCD
the uno itself runs very cool
you must provide external power for lots of LEDs, motors or other high power things
the uno itself is fine forever on a USB
but not if you are running motors or tasers off it
is there a glitch where TX and RX will stay on?
and taser are turned on by a servo
some 10 dollar one
BUT IT HURTS
for 10 seconds
a small servo is fine, larger or more need external power
so like a 9g servo max
you want to draw less than 250mA to be on the safe side
okay
well thanks for helping me
I have to study for my math quiz
and sleep
I didn't realize the time
it is 10:17
well bye
ok, good luck!
hey guys I'm having trouble understanding the concept of timer1 regarding how it should be utilized in code.
what makes it so different from using something like
auto time = millis()
to be used in a time sensitive macro for instance?
Like I guess the analogy that this website describes it makes sense but the rest isn't clicking for me
This website
https://deepbluembedded.com/why-use-timer-instead-of-delay/
This is an example of a function I have
void shineshine(){
auto time = millis();
while ((millis() - time) < 9){
senddownb();
}
while (((millis() - time) > 9) && ((millis() - time) < 12)){
sendjump();
}
while (((millis() - time) > 11) && ((millis() - time) < 80)){
senddownb();
auto time = 0;
}
}
My goal is to integrate timer1 instead of time = millis()
I have to say - I found that site's descirption to be very convoluted and poorly presented. And, er, it didn't even give a working example of using HW timers - nor explain why it can make things harder - since coding with interrupt routines is tricky and requires more complex code.
Furthermore, really, for things like sequencing actions like your shineshine does, there are simpler, more clear ways to handle it while still allowing you interleave other processing.
But - @formal cradle - if you don't need to do anything else while shineshine is running, there is nothing wrong with writing it using millis() as you have (though I could make some suggestions for making the code more readable.)
void shineshine() {
auto start = millis();
while (millis() - start < 9) senddownb();
while (millis() - start < 12) sendjump();
while (millis() - start < 80) senddownb();
}
assuming you want to mash on downb and jump as fast as possible during those intervals
@obtuse spruce Thank you so much for taking the time to respond to me! I guess my issue was that the function I'm running along with the intended game doesn't seem to do the inputs fast enough or at the right time despite using milliseconds. So I had thought that using something like timer1 would remedy that problem. I mean there can be other variables that can affect the timing like the polling rate in the game but I don't know how to measure that let alone use that info and utilize it in my code
But I think I'll try to just keep playing around with the timings
Do you have any recommendations on resources that explain timer1 to a first time/ amateur programmer like me?
Hey everyone. I started Uni a month ago (meng), and while every other subject is going well for me, I am completely lost at arduino and I am going to fail my first assignment. Which I came to terms with, but I am looking for a good place to learn. Since my tutorials got really complicated (for my level) from week 2 already, I am absolutely lost. Hopeless. Youtube tutorials also make me lost, so is there a tutorial series that explains everything like I am a 3 year old? I really want to overcome this terrible start and I have no idea what the best place is...
The uni assumes you did some coding in school, and I have not, so every little coma, every little operation is a new concept for me. I can copy code, but even if I do, I don't understand it and if there is an error, well, you can be sure it is there to stay because I can't fix it ever
@dapper swan do you have hardware to play with? You can also use tinkercad to play around in simulation.
I have a few beginner setups in tinkercad you can mess with https://www.tinkercad.com/things/bBMa3QYDtHS-blink-is-hello-world/editel
yeah i have tinkercad access
i was looking for some babystep tutorial videos that explain very few new things in each video
if i just stare at a code i won't understand anything
try adafruits arduino lesson : https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-1
@dapper swan
Don't just stare at the code, read the comments, they explain what every line does :
This program blinks pin 13 of the Arduino (the
built-in LED)
Try to make the LED blink FASTER!
*/
void setup()
{
pinMode(13, OUTPUT); // tell the arduino that pin 13 for OUTPUT
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}```
thanks i will give that a go
wow, that's a very programming centric problem.
@dapper swan
the problem is in line 3
Or in line 2.
The first error says that you can't actually do Serial.read(scores[i]).
So I guess line 5 is also wrong 😄
hmm. oh yeah i guess not.
But it looks like there are other problems with the code too, such as missing braces.
You'll need to share your entire code, @dapper swan
yeah, that code doesn't look like it was actually supposed to even run. Trying to read a float from the serial is not a basic task for a beginner arduino course.
@dapper swan
Well, there is Serial.parseFloat() that's supposed to do this. Maybe this API changed over time and that code is for an older version, or perhaps even their own Serial class?
I don't think Serial.read was every supposed to have the receiving variable passed into it as a parameter though 😉
Probably not, but you could rewrite parseFloat as read(float&).
@dapper swan so that is your assignment to find the faults in that code snippet ?
yeah i changed it a bit
no errors now but the monitor doesn't display what they want, i think
Keep in mind that we don't know what you're actually supposed to do 😉
well, it's kind of a difficult first assignment for a beginner arduino class but you are in uni so they've got to challenge the kids who already know some things.
@dapper swan
but you'll def. get some points if you fix the error on line 6. read this article to learn about it https://en.wikipedia.org/wiki/Zero-based_numbering#:~:text=Zero-based numbering is a,mathematical or non-programming circumstances.
Zero-based numbering is a way of numbering in which the initial element of a sequence is assigned the index 0, rather than the index 1 as is typical in everyday non-mathematical or non-programming circumstances. Under zero-based numbering, the initial element is sometimes term...
it's a long way, these professors assume we have a basis of programming knowledge, but truth be told, I haven't studied programming in over 14 years
we have a free week next week, so i can spend it trying to understand arduino better
// defines pins numbers
const int trigPin = 4;
const int echoPin = 2;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
I need help
my code is showing "distance 0"
I'm not sure if my code is bad or my sensor is shot
(it gave some smoke)
for simplicity make duration and distance floats
okay
but is the code good?
is it okay if you check it
so i can see if my sensor is shot
Then try thecode with floats
@blissful meadow are you using one of the common HC-sr04 sensors? which arduino are you using?
@blissful meadow your code will not work if you dont make the variables floats
so where should i put it
float duration;
float distance;
place it instead of the top lines
where on the top lines?
long duration ....
?
lines 5 and 6 in code you posted
Hello. I need some help with PROGMEM and classes.
In my sketch:
I have TestClass.h
#include <avr\pgmspace.h>
#include <stdint.h>
class TestClass{
public:
TestClass(const uint8_t arraySize, const uint8_t ***valueArray);
uint8_t GetSize();
uint8_t GetValueAt(int y, int x, int b);
private:
const uint8_t arrSize;
const uint8_t valArray[][3][2] PROGMEM;
};
I also have TestClass.cpp
#include "TestClass.h"
TestClass::TestClass(const uint8_t arraySize, const uint8_t ***valueArray)
: arrSize{arraySize},
valArray{valueArray}{}
uint8_t TestClass::GetSize(){ return arrSize; }
uint8_t TestClass::GetValue(int y, int x, int b){
return pgm_read_byte(*(*(valArr+y)+x)+b)
}
And my sketch.ino
#include <TestClass.h>
const uint8_t testValues[][3][2] PROGMEM =
{
{{100,2},{5,0},{10,4}},
{{1,20},{35,128},{10,5}},
{{5,10},{1,5},{12,5}},
{{20,1},{151,59},{12,5}}
};
const TestClass testmember(4,(uint8_t***)testValues);
void setup(){
Serial.begin(9600);
Serial.println(pgm_read_byte(*(*(testValues+2)+1)+0)); //This line prints testValues[2][1][0], which is 1
//I want this part to print
/*
0- {100 2 }{5 0 }{10 4 }
1- {1 20 }{35 128 }{10 5 }
2- {5 10 }{1 5 }{12 5 }
3- {20 1 }{151 59 }{12 5 }
*/
//It prints seemingly random values instead
//ex:
/*
0- {148 238 }{137 255 }{137 96 }
1- {131 232 }{137 249 }{137 128 }
2- {129 131 }{112 128 }{100 128 }
3- {131 159 }{191 129 }{224 144 }
*/
uint8_t aSize = testmember.GetSizer();
for(int i = 0 ; i < aSize ; i++){
Serial.print(i);
Serial.print("- ");
for(int j = 0 ; j < 3 ; j++){
Serial.print("{");
for(int k = 0 ; k < 2 ; k++){
Serial.print(testmember.GetValue(i,j,k));
Serial.print(" ");
}
Serial.print("}");
}
Serial.println();
}
}
Thanks for your time & any help would be greatly appreciated
@keen lichen I think you should use arrsize(arraySize) and same with valarray in Testclass
Your three dimensional array is going to be problematic, as you have to define (and act on) RAM vs PROGMEM for each of the indirections.
For PROGMEM stuff, you're generally better off using 1-dimensional arrays so you can avoid those problems
so if I were to approach this with a 1d progmem array it would work?
I think so. You'd change your uint8_t *** pointer to a pointer to PROGMEM uint8_t * or somesuch, and your read line would be something like ```arduino
pgm_read_byte(((i * NCOLS) + j) * NROWS) + k)
Thank you very much. I’ll try doing the same thing with 1 dimensional arrays when I get back to my pc.
I have changed
TestClass.h to
#include <avr\pgmspace.h>
#include <stdint.h>
class TestClass{
public:
TestClass(const uint8_t arraySize, const uint8_t *valueArray);
uint8_t GetSize();
uint8_t GetValueAt(int y, int x, int b);
private:
const uint8_t arrSize;
const uint8_t valArray[] PROGMEM;
};
And TestClass.cpp to
#include "TestClass.h"
TestClass::TestClass(const uint8_t arraySize, const uint8_t *valueArray)
: aSize{arraySize},
valArray{valueArray}{}
uint8_t TestClass::GetSize(){
return aSize;
}
uint8_t TestClass::GetValue(int y, int x, int b){
return pgm_read_byte(valArray+((y*3)+x)*2+b);
}
and my sketch.ino to
#include "TestClass.h"
const uint8_t testValues[] PROGMEM =
{
100,2, 5, 0, 10,4,
1, 20, 35, 128, 10,5,
5, 10, 1, 5, 12,5,
20, 1, 151,59, 12,5
};
const TestClass testmem(4,(uint8_t*)testValues);
void setup() {
Serial.begin(9600);
uint8_t aSize = testmem.GetSize();
int x = 2, y = 1, z= 0;
Serial.println(pgm_read_byte( testValues+((x*3)+y)*2+z ));
Serial.print("Size of array is: "); Serial.println(aSize);
for (int i = 0; i < aSize; i++){
Serial.print(i+1);
Serial.print("- ");
for (int j = 0 ; j < 3 ; j++){
Serial.print("{");
for (int k = 0 ; k < 2 ; k++){
Serial.print(testmem.GetValue(i,j,k)); Serial.print(" ");
}
Serial.print("}");
}
Serial.println();
}
}
I can get every value I want using pgm_read_byte( testValues+((i1*3)+i2)*2 + i3)
but doing testmem.GetValue(i1,i2,i3) still seems to return random values.
I'm guessing valArray isn't being set correctly
I would expect something like arduino valArray = valueArray; in the class constructor, I'm not sure what valArray{valueArray}{} is supposed to do
You could also print out the values of testValues and valArray to see if they match
To be honest I don't know c++ that well to know what valArray{valueArray}{} does
however doing valArray = valueArray; gave an error :
error: assignment of read-only member
I saw the solution above used by anoter arduino library
You are right though, it might not actually be saving the values in progmem that way
I'll research a bit. brb!
Oops. I did a newbie mistake.
So, the solution of class_variable_name{parameter_variable_name}, is correct for basic variable types, however for arrays/structs/classes/anything that isn't a basic type needs to be written like: class_variable_name(parameter_variable_name),
Welp, thanks for all the help!
I didn't even think of the issue being so simple.
Thanks for sharing what you found, I learned something!
So, I bought the kits and assembled this, but I don't know where to go from here because the guide just tells you what to buy and then gives you code. https://learn.adafruit.com/arduino-hunt-the-wumpus/overview-and-parts
can someone @ or DM me an Ardruino for Dummies (for Linux preferably) so I can catch up to where this guide thinks I am?
@quaint spire what are you stuck on?
http://learn.adafruit.com/category/learn-arduino
maybe start with Ladyada’s Learn Arduino Lesson #0
Perfect! @silver stirrup thank you
I don’t actually know any good guides/lessons that teach arduino but I’d go with the examples on arduino’s official site.
I just got an arduino about a week ago and here is how my learning experience was like:
Day 1: use 5V and GND to turn on a led on a breadboard
Add a button to control the led
Try the flickering led example(and read the code)
Try the analog read example (and read the code)
Try connecting a 7 segment display
Accidentally destroy the 7 segment display because i didn’t add any resistors in between +5V to GND
Day 2: feel sad because you already destroyed one of the components, but hey... the arduino itself still works so it’s ok... and order some more parts to experiment with
Try some of the other examples
Learn about resistors, transistors, capacitors, other components
Day3: make simple circuits, try potentiometers, etc.
Check the arduino reference pages. The programming referece page is really easy to understand.
Day 4: more components arrive.
Try the piezo buzzer! It needs ~100 ohms of resistance. I wire 3 330 ohm resistors in parallel to get ~110 ohms It works, cool!
Play some tunes on it.
Use the new 7 segment you just ordered... make a counter. Make it go up, make it go down
Combine the analog read example with 7 segment to display the readings on 7 segment instead of through serial!
Day 5: try to get a nokia screen working with your arduino. It works! Wow. Draw images on it or something.
Add some buttons to it and make a simple game!
Start writing a library to test your knowledge/skills
It’s now day 8 for me and i’m still working on a library.
Yeah, there is a lot to learn to be proficient, more than five days. Dont be bummed, none of us were born knowing how to do this either, and it takes a long time. I spend every day working with embedded systems, some libraries take multiple full time days to get it done and validated. You are working not just with low level systems programming languages, but also within a constrained environment, and with the hardware directly, hardware is hard, but rewarding. In fact, its amazing you went through all of that in a few days, shows how the Arduino framework allows people to jump right in without hitting the learning curve as hard as if you were just left with a compiler.
Indeed. There is a lot more to learn.
Arduino is designed and documented so incredibly well, that it allows people to start building/wiring whatever they want right away and learn along the way.
I expected weeks, maybe months of reading manuals, data sheets and visiting countless forums to even build the simplest of things. I was and still am very happy that it isn’t that way. Learning as you go is much more fun. In fact, I believe learning and being able to experience your progress along with the mistakes you make, make a better teacher than just reading tons of documents.
Hello! I am glad to join this community!
I am working on a project about bluetooth connectivity. The target is to extract data from a certain hospital device and broadcast BLE signal.
I have an ESP32 with me and i can probably set up the BLE service without issue. The issue is the extract data bit.
I am given 2 options: using the LAN port or the USB port.
Let's focus on the USB first (I will be using Arduino Mini USB Host). I currently have a SDK in .dll format as well as example code on how to transmit data through USB to Window OS. But for ESP32 I probably need to write up my own USB driver/interface. How difficult is it?
A second problem is that I don't have a clear idea of what exactly I need to write a driver/interface. Does anyone have any example? Thanks in advance!
(Not sure if this is related to Arduino. But since ESP32 can use the Arduino IDE, I assume they are similar? If not please kindly redirect me. Thanks!)
Presumably there's a driver available for ESP32 already.
I know that there is a TinyUSB library that can be used to turn arduino-like board into usb HID, mass storage, and more. Maybe it already has the drivers you need
it doesn't support esp32, but it supprts nRF52840, which also has bluetooth
actually, it supports esp32-s2
Hello, I've got an ESP32 working with a PCA9685, and I want to add an LCD character display with an I2C controller attached. Is there anything extra I have to do to use both of them at once? Just connect both of them to SCL and SDA? I notice the PCA9685 and the LCD display have 'I2C address' jumpers, do I need to mess with those?
check in documentation what is the default i2c address for each of them. if they are different (which is almost certainly the case), then you do not have to do anything at all
Oh ok, great. I'll give it a go, thank you
just make sure you only have one set of pull-up resistors on sda and scl lines, not two
Hm I don't currently have any, didnt even know I needed one of those, the PCA9685 is working fine though, suppose there is one built into my PCA9685?
yeah, if you are using adafruit breakout, itvsays
"has weak pull up to VCC"
pullups are required for i2c
Would love some suggestions of "best MQTT" library for arduino with an ESP32 unit
TIA
ESPMQTT isn't compiling :/
/Users/foo/Documents/Arduino/libraries/EspMQTTClient/src/EspMQTTClient.cpp:272:13: error: 'class EspClass' has no member named 'reset'
ESP.reset();```
^
well that's annoying. The latest version 1.10 has that bug. 1.08 seems to work.
Hmm apparently the Teensy 4.0 comes with a packaging which says "assembled in USA", wondering about the Teensy 3.0. PJRC is a USA company but all their listings online tend to say "Country of manufacture: Unknown"
Actually all the ebay listings for ATmega32U4 boards are either made in china or unknown
adafruit makes their boards right here in NYC. But they don't sell them on ebay.
@north stream Unfortunately my device use an interface that is vendor specific, and hence there is not any existing library.
Suppose I got a COM Port Interface document with me.
With that I can write a python code to send USB request command to my usb device.
"""
import time
import usb.core
import usb.util
VID = 0x10c4
PID = 0xea60
device = usb.core.find(idVendor=VID, idProduct=PID)
response = device.ctrl_tranfer(reqType, bReq, wVal, wIndex, data)
"""
Do you know the equivalent in C++ using Arduino USB Host Shield Library (or any other library)?
Is it something like this?
rcode = Usb.getDevDescr( addr, 0, 0x12, ( char *)&buf );
or something like this?
ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, NULL)
(Sorry if this is confusing. Please let me know if I am being too vague here.)
I just got an arduino about a week ago and here is how my learning experience was like:
@keen lichen I did my skip-the-resistors phase with a very expensive electronic lab my step dad bought me in middle school. 😅 I guess this Hunt the Wumpus kit is something I should have got day four, not day 0. I'll catch up! I have the time on my hands for now.
@quaint spire
At least we are both learning.
@keen lichen behold the power of help and coffee!
@keen lichen @quaint spire I'd say you two are fast learners and thanks for documenting your journeys, it'll help others to shy to post. (Coffee is wonderful for coding, not so much for surface mount soldering 🙂 )
@reef ravine flattery will get you everywhere. I feel like the hardest part was knowing what wont ruin everything. If I knew I could just put power to the Metro, I might have figured a lot of the other stuff out, but I didn't want to ruin it. I'm on a schedule. I got the POV kit working Saturday, running a new image yesterday, Wumpus is working as of today, tomorrow I'm replacing microswitches on my trackball mouse and I'm hoping to be bored with everything by the time the new Adabox shows up.
Very cool, POV is on my list of "one day". It's amazing what can be done with a few dollars of hardware these days. I got back into this hobby a few years ago, after arduino came out. In 1975 a 4K memory board was $100, now my local Microcenter gives out 32GB thumbdrives for free...
(Coffee is wonderful for coding, not so much for surface mount soldering 🙂 )
@reef ravine hmm... never tried to surface mount coffee before. That's an interesting idea.
@vivid rock lol, yeah in that sense coffee and PCB's definitely don't mix
I was having a hard time connecting two DC motors through the Spark Fun Qwicc motor controller to the Arduino MKR1010? Could someone help with that?
@hasty bay can you be more specific? how is everything connected, what code you use, what problems are you having?
I'm having trouble getting my SD card to initialize using the adafruit microsd breakout board with the cardinfo example code, could anyone help me figure out why?
I have the connections like this right now:
Connect the 5V pin to the 5V pin on the Arduino
Connect the GND pin to the GND pin on the Arduino
Connect CLK to pin 13
Connect DO to pin 12
Connect DI to pin 11
Connect CS to pin 10
I'm also using a nano 33 BLE, but I have tried using a UNO for troubleshooting, as well as a new SD card and rewired the circuit
What kind of card? What error message?
I'm using this SD card
https://www.amazon.com/gp/product/B07K81Z6DF/ref=ppx_yo_dt_b_asin_title_o08_s00?ie=UTF8&psc=1
It's format type is FAT32 and I'm not getting any error message except the initialization failed because the card info example code only returns that
Is this the breakout board ? https://www.adafruit.com/product/4682
https://www.adafruit.com/product/254
It's this one
I can post a picture of the circuit as well if that'd help
In the details it says “Go to the beginning of the sketch and make sure that the chipSelect line is correct, for this wiring we're using digital pin 10 so change it to 10!” Just checking if that could be it
I changed it to 10 already
Cool
I should mention that I ran the card info last night and it was working
That's why I'm even more confused
Can you use openCV with arduino?
It's really targeted at systems that have a full OS.
You can implement some of the functions used in opencv on the arduino though
Hey all, I'm getting back into Feather and Arduino after some time away. I'm using a Feather Adalogger M0 with the Neopixel Friend Feather for the 5V shifting. My laptop is plugged into the M0 and is providing power. The power for the WS2811s is separate, though the grounds are tied together at the WS2811 strand start. Anyway, my issue is that Arduino IDE often fails to put the M0 into debug mode for code download. So I have to push the button and manually specify the alternate serial port. Is there any easy way to make this work all the time? It's so nice when it works.
Here I am, once again, asking for help.
I wanted to ask if it was possible to have an instance of a class in another file... (a .c file for example)
Here's what we can do and how we can do it:
If I have a file called data.c
in the root folder of my project containing:
#include <avr/pgmspace.h>
const uint8_t data_arr[] = {0x01, 0x02, 0x03};
int arr_size = sizeof(data_arr); //this works since sizeof(uint8_t) is 1
//generally it's better to do sizeof(data_arr)/sizeof(data_arr[0])
and if my project.ino file contains:
extern const uint8_t data_arr[];
extern int arr_size;
void setup(){
Serial.begin(9600);
for (int i = 0 ; i < arr_size; i++){
Serial.println(pgm_read_byte(data_arr+i));
}
}
I get the expected output:
1
2
3
.
however what I want to do is something more like this:
data.c:
#include <avr/pgmspace.h>
#include "TestClass.h"
const uint8_t data_arr[] = {0x01, 0x02, 0x03};
const TestClass dataMember(3,data_arr);
^^^ I tried the code above and I get a ton of errors...
Here are some of the errors:
class SPISettings {
^^^ arduino somehow not being able to include it's own libraries?
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src/SPI.h:72:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class SPISettings {
^^^ continuation of similar errors (there are lots of errors about both arduino's & my headers, not pasting the rest)
finally near the end I have these errors regarding my includes...
4by5fnt.c:190:7: error: unknown type name 'PGE_Mini_Font'
const PGE_Mini_Font font4by5fnt(0x04,0x05,0x81,(uint8_t *)data4by5fnt);
^~~~~~~~~~~~~
4by5fnt.c:190:33: error: expected declaration specifiers or '...' before numeric constant
const PGE_Mini_Font font4by5fnt(0x04,0x05,0x81,(uint8_t *)data4by5fnt);
^~~~
4by5fnt.c:190:38: error: expected declaration specifiers or '...' before numeric constant
const PGE_Mini_Font font4by5fnt(0x04,0x05,0x81,(uint8_t *)data4by5fnt);
^~~~
4by5fnt.c:190:43: error: expected declaration specifiers or '...' before numeric constant
const PGE_Mini_Font font4by5fnt(0x04,0x05,0x81,(uint8_t *)data4by5fnt);
^~~~
4by5fnt.c:190:48: error: expected declaration specifiers or '...' before '(' token
const PGE_Mini_Font font4by5fnt(0x04,0x05,0x81,(uint8_t *)data4by5fnt);
^
exit status 1
unknown type name 'PGE_Mini_Font'
Weird thing is, if I have #include "MyClass.h" in the .ino file, there are no errors. and I can actually use the functions in the class.
However, when I have the #include "MyClass.h" in the .c file, there are all sorts of errors, doesn't compile.
If I get rid of #include "MyClass.h in the .c file, then it doesn't compile because it doesn't know the type MyClass.
The .c file may need some explicit #include statements that the .ino file gets automatically
I have been thinking that as well, I tried my luck with Arduino.h , stdint.h (for uint8_t)
and a few more
I'm still experimenting with combinations
I'm kinda suspicious that it's because I'm trying to create an instance of a class in compile time by forcing const...
There could also be some sort of #define conflict (those can be annoying)
Sometimes I'll chase them down by getting dumps of the postprocessed files and examining them
would define guards help if so?
Probably not, usually you need to rename things to avoid conflicts, or use #undef to remove the problematic ones
oh I see what you meant by #define conflict
alright, so...
idk what actually happened.
I moved the c file into another folder and tried compiling without it. It didn't compile... I went ahead and checked the headers and cpp files one by one. Didn't compile at all... I decided to pull that "turn it off and on again" trick. Closed the ide, relaunched it. It compiled.
Added one header back, it compiled.
Added all the headers, it compiled.
Added the c file. It compiled.
I'm kinda curious what went wrong the first time though...
did you make offerings to the elder gods this month?
sometimes if you forget things like this can happen
they don't have a ton of power in modern times, but they have some
Ah, that must be it.
partial to macaroons I've found
Ah now I'm having another weird issue. but it's probably got something to do with my spagettified code.
Hey guys can you recommend me good PID library for arduino (or avr in general) ?
the LED from the arduino nano turns off when i plug in the power to my 5v displays
are these the correct upload settings?
If your Arduino turns off when you plug something in, you're probably plugging it into the wrong place or the thing you're plugging tries to use too much current.
yes i think it was the wrong place
hmmm serial monitor is printing this in a loop
pP�@pP�@pP�@pP�@pP�@pP�@pP�@pP�@pP�@pP�@pP@pP@pP@pP@pP@pP@pP@pP@pP
Using this sample code https://pastebin.com/XfCGevBN
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i'm on baud 9600
You must connect the nanos ground to the displays
What does the red light on the last display mean
this is what the guy who made it said:
There are three leds (I only soldered one on yours, iirc I think the one that indicates the module is processing a serial command). I cant remember off the top of my head what the other two do (probably debugging related I'm sure).
I have the D1 tx on the nano connected to rx of the 3 boards
To start off, thanks to JLCPCB for sponsoring this video as well as providing pcbs to get the ball rolling on this project. JLCPCB Prototype for $2 (Any Color): https://jlcpcb.com
Additionally I'd like to thank Alfa Zeta once again for donating the electromechanical displays ...
The problem seems to be in the code
here is a timestamp. it seems mine may be plugged in the wrong order? https://youtu.be/nZQSqFpyLaE?t=73
To start off, thanks to JLCPCB for sponsoring this video as well as providing pcbs to get the ball rolling on this project. JLCPCB Prototype for $2 (Any Color): https://jlcpcb.com
Additionally I'd like to thank Alfa Zeta once again for donating the electromechanical displays ...
but i feel it should not make a difference
also in the video, he does not seem to ground the displays RX
Try this code https://pastebin.com/NkdNKc0z
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ok i will try it out
There is no documentation on how addresses are assigned to the displays
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this is the driver on the displays
Yes, but you need to know the address that is assigned to every display, it is not in the code
when i upload the code it should in theory start driving the displays correct?
yes, it should drive them
i shouldnt have to disconnect the power or the nano
no, dont disconnect it
Display does not do anything?
correct
Ok, try this https://pastebin.com/bpPUReCv
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Yay, I got most of the stuff working!
This one tests all addresses, it should somehow work https://pastebin.com/5BV4iRuF
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Does anyone know if it's possible to control piezo speakers volume while still using tone() function?
I think the tone function just does digitalWrite()...
hm
@sweet sleet the code should take only a few seconds. Try this version https://pastebin.com/DsTmN79a
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
What if you disconnect two of the displays?
still nothing...
when i unplug the power and plug it back in while holding the button on the back of the display the display will count up from 00 to 99
but that is because the code is loaded onto the the actual display
but that shows that the 12v is working fine
it also, when i restart and plug back in, will clear the display
Is the TX of nano connected to RX of the display?
This is really strange 🤔
I wonder what the issue could be since I've tried different controllers
maybe it's the serial line on the modules
hey!!! i plugged it into one display and it types out weird stuff
Well, i’m an arduino noob.
Oh hey, cool
when i unplug the power and plug it back in while holding the button on the back of the display the display will count up from 00 to 99
@sweet sleet
Is it doing this?
but that is because the code is loaded onto the the actual display
@sweet sleet maybe because of this
i unplugged at 79
i'll now plug back in
it clears
then starts at 86
it might be the battery retaining the number!
What code do you use?
It might be that. Or maybe the value isn’t initialised before counting.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i plugged it in only to display numbered '0'
so it's only 1 display
What! Pastebin got banned in my country... when.. why.. how?
i tried using the same code on display numbered '2' and it doesnt work
OH i know why it's continuing.
i only unplugged and replugged the power. NOT the nano
oh no... display 3 i can hear the toggling of the coils but it won't change
no. it's buggy.
You don’t need to have
while(1) on void loop() by the way, that’s what the loop function is for.
good point. i didn't write the code
display 0 is the only one that works
the same code won't work on the d1
Is this part trying to separate a long or int (temp) into 6 digits?
digits[5]=temp/100000;
temp=temp%100000;
digits[4]=temp/10000;
temp=temp%10000;
digits[3]=temp/1000;
temp=temp%1000;
digits[2]=temp/100;
temp=temp%100;
digits[1]=temp/10;
temp=temp%10;
digits[0]=temp;
If so, that’s not the right way to do it.
This however would split the number into digits.
currentDigit = 0;
while (temp>0 || currentDigit <6){
digits[currentDigit] = temp%10;
currentDigit++;
temp /= 10;
}
Yes agree it’s cleaner but now that nothing works i just keep it as is since it works in theory
Hm. Maybe you need to clear screen every time you want to write new data?
I’m not entirely sure but that might be a possibility
Or, if the display doesn’t require serial(by that i mean specific baud rate), you could try sending data through mosi? (Though you may need to try different clock divisions for SPI for that to work, or it might not work at all.)
@sweet sleet
The display is controlled through serial
Shoot
Its no longer working
Okay it works again
I think there’s not enough power to drive more than one display??
Hmmm
For the other displays it just displays 0
It could take some timr since display 0 is the first 2 digits???
yes
I wonder if you have been having power issues all along
ayy!
I'd put up a confetti reaction but I'm on my phone. Congratulation, well done!
Well done. What fixed it though?
@sweet sleet yeah what fixed it ? was it power issue ?
hey guys! sorry i was muted for tagging a bunch of people to thank them.
it's possible that it was not working with the original board because I didn't have it grounded
or i think it's just the original D1 board would not work.
would this same code that works for the nano work with the wemos D1 esp8266? https://pastebin.com/XfCGevBN
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
omg it works on my nodemcu with 3.3v!!!
well i'm using the 5v actually from the separate controller
OH how do you change the tx line so it's not connected to the serial output??
esp 8266 nodemcu
like how do i programmatically change the tx on nodemcu
Software serial
excuse me if this is an insanely stupid question, but i'm not sure how to solve my problem. I have 4 buttons, and i need to store the input sequence in an array to compare it with another.
int i = 0;
while (i<=n){
if(digitalRead(7)==HIGH){
inputSequence[i] = 13;
i++;
}
if(digitalRead(6)==HIGH){
inputSequence[i] = 12;
i++;
}
if(digitalRead(5)==HIGH){
inputSequence[i] = 11;
i++;
}
if(digitalRead(4)==HIGH){
inputSequence[i] = 10;
i++;
}
delay(10);
}
Here's the code i've put in a function. n is a global variable and inputSequence is the array i'm trying to store the sequence in. The problem is, whenever I press a button, the loop just stops
assume this is within ```C++
void loop()
no, this is in a separate function
what do you initialize n as?
or rather do you know the value of n when you enter the loop?
n is initially zero, but it increments every time void loop() loops
how long is your void loop()? is it postable?
sure is
hold on
void loop()
{
makeSeq();
dispSeq();
for(int i=0;i<=n;i++){
Serial.println(sequence[i]);
}
inputSeq();
if(n<maxBlips-1){
n++;
}
else{
n=0;
}
}
the function in question is inputSeq()
int buttonState7 = 0, buttonState6 = 0, buttonState5 = 0, buttonState4 = 0;
const int maxBlips = 5; //Set the maximum number of levels here
int sequence[maxBlips];
int inputSequence[maxBlips];
int n = 0;
is loop() the only place where n is modified?
yes
I'm not seeing inputSeq() called anywhere, where is it called?
10th line in void loop()
lol mybad
my logic, and i feel like there's an issue with this, is that the while loop will continuously loop until a button is pressed, at which point the pin number will be stored and i will increment
i'm also open to other approaches
Software serial
There are two methods, the simple method is to use:
shiftOut(dataPin, clkPin, bitOrder, data(byte))
bitOrder can be either MSBFIRST or LSBFIRST.
You don't have much control using shiftOut.
The clock speed of shiftOut varies but I measured it to be about 1/8th the clock speed of arduino models if you are sending only 1 byte.
If you send more bytes, the time it takes the data to be sent through shiftOut will depend on how effective your code is. (How you access data, do you modify data before sending, etc) There's also shiftIn for when you want to read data!
Then there's a header that I haven't touched yet called <SoftwareSerial.h>
you first initialize an instance of SoftwareSerial using SoftwareSerial softSerial(pinRX, pinTX) (can be any of the digital pins)
You set the baud rate & other variables if you need to...
softSerial.begin(9600)
You can then use software serial almost as if it's a hardware serial. It supports similar functions:
print, println, write, read, etc.
@sweet sleet
I don't know tbh.
i got it working very well i didn't use a second softwareserial but I just deleted all the serial.print commands
i would have to ground it too if i did right
these wires are getting tricky
does someone have an alternate solution to my problem, or is there something wrong with my logic?
I'm not 100% sure why it's not working, it seems sound? But are you intending for inputSequence to be overwritten every time?
Are there good series cables i should use to organize these
I also have two power sources
yes inputSequence is overwritten every time it's called
just to make sure I'm not misunderstanding, what's the behavior you're actually seeing?
so i run the program, everything works smoothly until i call inputSeq()
where i want multiple buttons to be pressed before the program continues, i can only press once
that makes sense for the first loop since n = 0 and i++ would make your while conditional false
*first call
hm
Oh, I timer's up I can type.
Hello all, hope you're having a lovely day.
I'm looking to play around with expanding external memory with an EEPROM and I'm trying to understand how to identify chips which will work with the arduino UNO. From my research so far I believe the criteria for this involves clock speed and that we have I2C available, though I believe that's pretty much the standard. I can't say I fully understand how clock speed interaction works other than that I'm aware timing is a big deal, I just don't fully understand it (yet).
So, if anyone has any information about this they'd be willing to share, that would be awesome.
I'm just interested in figuring out what options there are. I also have to explore how addressing plays in to this since I don't really have a solid understanding of limitations on addressable space.
@uneven nova looks like it just zips through the loop filling up the array when the first switch is pressed
even with the delay?
@north stream you mean the moment i press the switch it fills the array with random numbers and doesn't allow for more inputs?
Oh i see, it fills the entire array with the button number i pressed
So how would I make it wait for an input after the first press?
The short answer is, wait for the switch to be released again before continuing.
The longer answer is you should probably use either a debouncing library or a delay, so switch bounce doesn't act like several very fast presses in a row.
Well that solved it (for now)! Thanks for the help guys
just madbodger lol
thanks for inputting lol
i'll make sure to debounce my input next
ha nice
I have a feeling that knowledge grows exponentially as you experiment with various components.
Just wired up a flip-flop (properly) for the first time and I feel like I gained a lot more from the process than I expected.
Hii guys can anyone say witch Arduino should I purchase or which one is more beneficial
@leaden light what are you wanting to do?
Hey all, I'm getting back into Feather and Arduino after some time away. I'm using a Feather Adalogger M0 with the NeoPxl8 Feather (for the M0) for the 5V shifting. My laptop is plugged into the M0 and is providing power. The power for the WS2811s is separate, though the grounds are tied together at the WS2811 strand start. Anyway, my issue is that Arduino IDE often fails to put the M0 into debug mode for code download. So I have to push the button and manually specify the alternate serial port. Is there any easy way to make this work all the time? It's so nice when it works.
@gilded swift i am a beginner so i want to do small project
Ohhk ty
😄
What a cutie pie! Or is it... a QT Py? This diminutive dev board comes with our favorite lil chip, the SAMD21 (as made famous in our GEMMA M0 and Trinket M0 boards).For a limited time: only ...
Out of stock at the moment but they have more coming
👍🏻, hmm
can someone make this make sense?
I would advise against arduino uno. It is large, slow by todays standards, and expensive. Get one of adafruit feathers or Arduino nano 33 boards. If you do not need wifi or bluetooth, nano 33 every is cheap and quite nice
qt py is probably the best choice price wise, it does seem like a nice little board
@obtuse goblet What are you referring to?
Your best bet might be to do it a minute at a time, and count intervals: ```arduino
#define MINUTE (60 * 1000) // one minute in milliseconds
static unsigned long next;
static unsigned target = 60;
void loop() {
unsigned long curtime = millis();
if (curtime > next) {
target -= 1;
if (target == 0) {
// do your once an hour thing here
target = 60;
}
next = curtime + MINUTE;
}
would this work
const long oneSecond = 1000; // a second is a thousand milliseconds
const long oneMinute = oneSecond * 60;
const long oneHour = oneMinute * 60;
then..... delay(oneHour);
Alternatively, you could just set next to an hour in the future: ```arduino
static unsigned long next = millis() + 60 * 60 * 1000;
The delay() call is mostly for brief intervals, which is why I like to use millis() for longer times. A side advantage to doing it that way is that you can have the processor doing other things while it's waiting, or (if you want to get fancy), you can modify the code to have the processor sleep when it's not doing anything.
hmmmm okay i want my loop to do a function every 30 minutes or one hour
excuse the foul language lol
this would be every 1 minute right?
oh there's a bracket missing
how long are you planning on having your code run?
forever
what
real time clock
i'm not sure how to handle that
This project is to give a practical example of using power save modes with Arduino's. It uses a Real Time Clock (RTC) to wake up an Arduino Data Logger. It write the temperature and humidity in a room to a micro SD card. It is optimized for saving power thus can run of a batte...
the reason is that the clock on the arduino is going to drift over time and your 30 min/60 min timer will become less and less accruate
accurate
then indeed using millis() is fine
do i need to import date time or something
To use an RTC, you'd probably use a library, but millis() is built-in
Hey all.
@sweet sleet time since board restart, in milliseconds
I was just experimenting with a counter/divider IC and I was having a lot of trouble getting it to operate as intended. I'd pulled a couple pins low (reset and clock hold) using 10K Ohm resistors as I'd seen done on a flip-flip IC I played with yesterday. I assumed this was standard procedure when pulling things up or down since I'm still overcoming ignorance. Turned out this was wrong and a direct path to GND was needed for correct operation.
I don't know how to identify when a resistor is needed, though I did read the datasheet to the best of my ability.
Perhaps I'm confused and the pins which I had to pull through resistors yesterday were active low, so I was pulling high through resistors... maybe that's when you need a resistor...
I should go review.
@sweet sleet note that millis() returns an unsigned 4-byte integer, which means its maximal value is something like 4 billion, which equals to (roughly) 45 days. So the value will overflow after 45 days
ah okay got it.
It does appear the pins on the flip flop were pulled high to inactivate them. So until I have better information I guess I'm going to assume if pulling high, go through a resistor, if going low, don't.
😛
static unsigned long next = millis() + 60 * 60 * 1000;
how do i then enact a delay for this amount of time
is it the same code as above
yes
ok
there was a bracket missing
i'm gonna step thru it now to understand it
Also for some reason these displays are showing the wrong value now 😔
Should be 4397 not 9797
What's the name of that type of display?
7 segment?
yes
mechanical
shoooooot!!! the second display is accidentally matching the first
That would be pretty cyberpunk
I was going to ask that 😄
What are you building with this?
@iron mason https://www.daliborfarny.com/
displays the total number of miles i've run
@reef ravine Read my mind
any idea how i'd go about fixing the address on the middle 2 digits?
oops wrong video
they can be had more cheaply as Soviet surplus
I just realized those "how to make acrylic enclosures" videos I watched for no purpose years ago suddenly are very interesting....
@reef ravine at over 1000 Euro per clock, this is pricey
i tried making an acrylic enclosure on this
but sooo beautiful 🙂 NOS tubes can be had much cheaper
Yeah a bit out of my technical range for the moment but I will come back to it 🙂
@reef ravine what is NOS?
Atm I'm trying to comprehend when to use a resistor for pull up/down 😛
New Old Stock, tubes in boxes from the 1970's
😦 do i have to flash the firmware on the PICs to fix the addresses?
it seems it got messed up
Oh good lord I think there was just some gunk on the resistor I was using -_-
There's no problem with pulling low via resistor which is what I thought initially
it seems the middle two digits are copying the rightmost two digits (the rightmost 2 digits are fine)
It seems the addresses may have changed for some reason! Is there a way to fix this?
Sure you're not just sending the wrong bits or something?
I assume you're shifting out portions of a 4 byte value to each display
Sorry m8 I just don't know anything about how your signal is passed or what addressing you're doing
no worries
i'll try to figure it out
here's the driver on the displays fyi
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
and rough sample code
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
could it be that the address somehow changed on one of these boards?
do you know how the address is set?
honestly no i dont.
some designs have jumpers/pads that you can connect to a signal (gnd or supply sometimes) to change the address
i will ask
i think it's possible that i accidentally changed it when i was touching and moving the thing
i was trying to put the whole thing in an enclosure
Programming the address is currently only possible through using an icsp programmer to flasht the eeprom
uh oh.
this is way too advanced for me.
did you make a change to the code that writes to the displays?
no
hm
suddenly one of the modules is responding as if it was another address
Hey guys, I just got a playground express but it doesn't appear to show up on Windows 10. I tried the troubleshooting options but I haven't had any luck. It does appear as a "other device" though.
I plugged in the Trinket M0 I bought as well and that seemed to be loaded fine.
hmm I'm not sure how to resolve the windows setup with the Playground Express. If anyone has any tips that would be appreciated!
If it was responding to the correct address before, and it's not responding to the correct address now and you didn't reflash it through ICSP, I suspect the problem is something else
Are you using the same usb cable on the trinket and the CPE?
no, I'll try the different cables now.
some are "power only"
both are the same brand. I bought 2x when I got the boards.
using the other cable didn't work.
worth a shot, power is there as you get BLE...
When double tap the reset button the playground goes red. Is that correct?
double tap should cause something to happen, does BOOTPY or similar now appear?
a CPE is next on my list, they were out of stock when last i checked
nah, I do hear the windows usb connect and reconnect sound though. So it sounds like it's doing something, but each time it reconnects I never see it as a drive in explorer.
take a look at Device Manager, does an unknown device come and go?
when connecting the trinket I do see the USB safely eject pop up in my tray though. With the CPE it doesn't appear.
nah nothing unknown in device manager, and nothing suggesting it needs a driver update
does it show up (erroneously) under Ports(COM & LPT)?
hmm mine is listed like so
ill try the steps though
thanks for your help so far
i tried anyway
yup
unplugging/replugging sees the COM6 entry disappear and reappear
uninstalling device and then resetting the CPE didn't do anything either. It was just relisted under ports the same.
Hmm, I'd move this to #help-with-circuitpython , somebody is likely to have encountered this before
okay thanks
Hi,
I have a few of the Infineon TLE493D sensors which I am trying to connect in an array through a basic Arduino Uno. Since the sensors, all have the same addresses 0x35, I attached them to the Adafruit multiplexer TCA9548A to send me flux changes data periodically.
The primary issue I am facing is, when I run my code, after several readings, it bricks.
I have been troubleshooting at a hardware stage and have realized that changing from one sensor to another, causes this issue.
I have a logic level converter attached to my system for safety precautions and have tried putting one sensor on the I2C bus and the other on the I2C through the Multiplexer to check the issue. The problem still persists. Please note the sensors work okay on their own as it is.
Can someone please help me with this situation? I am trying to attach multiple of the same sensors.
I wonder if the problem is on the sensor end or on the Arduino end (like in the sensor driver)
Also, are you using interrupts?
Hello, may I ask a question about the BNO055?
@dark shard yes, you may
Thank you kindly, give me a moment to organize my thoughts concisely.
@vivid rock
Okay, so I'm trying to use the BNO055 for a Madgwick filter. I think I'm all good on the quaternions and matrix multiplication side of it but I want to change the configuration into the operation mode config so I can change the accelerometer range from -4/4g to -8/8g. I'm just REALLY fuzzy on the procedure and syntax I need to do for that.
I have the Adafruit_BNO055.h library included and have made an IMU object. It is connected using the I2C bus to a nano. I'm confused on how I go about telling it to change the configuration. I found a tutorial that says to use Wire.beginTransmission() where the argument is the device address in hex and then do Wire.write() where the argument is the register address and then do Wire.write again with the new data I want put in but those are in hex and the datasheet from Bosch has it in binary.
Also the binary from the datasheet is 9 bits long and the tutorial says that Wire can only send 8 bits at a time.
The library for the BNO055 uses hex addresses though.
But when I try to access the class with:
Adafruit_BNO055::() I'm unsure if I should have an argument in there and it says I can't access the class when I try to verify.
So yes, any advice you have would be greatly appreciated and thank you in advance.
OK. First of all, why BN0055? Main selling point of this chip is that it already has sensor fusion in the chip - if you are using madgwick on the microcontroller, than you don't need that, so it sounds like a waste
why not use the fusion which is already on the chip then?
let me do a quick check of the datasheet and adafruit library
Thank you for checking that.
This is my first time playing with an IMU and I found Paul Mcormic's video series from TopTechBoy on youtube. He strongly stressed using the same equipment. We also went with this one since it comes already calibrated.
I'm not using the fusion modes because my understanding is that they will give me the roll pitch and yaw but I also want the controller to run a Kalman filter for trajectory aswell. The madgwick is for our orientation.