#help-with-arduino
1 messages ยท Page 74 of 1
@marsh rock You need to put ` around your code or else Discord messes it up.
ahhh thats why
so then i need to declare 2 new variables NUM_ROWS2 and NUM_COLS2
no thats discord messing up my code
hang on ill post it properly
int delta = (abs(NUM_ROWS*2) + abs(NUM_COLS*2))-(abs(NUM_ROWS - row * 2) + abs(NUM_COLS - col * 2));
that code inverted the first one, now the color starts from center and fades out to the edge
oh sorry i didnt read your whole message
i thought you wanted it reversed lol not left to right
@elder hare What does CHSV do?
int delta = abs(NUM_COLS - col * 2);
Oh OK. What are the minimum and maximum values you want to use for hue?
@marsh rock so close! what's happening is it split the "screen" in two so the colors come from both sides and into center
I guess 0-15
But you already have logic for this, @elder hare . In your XY() function.
yes ๐
leds[XY(col, row)] = CHSV(...)
oh, thats cause when col * 2 becomes greater than NUM_COLS (half way) the abs will force the negative number to be positive so it will just add up again half way across
but yea its kinda hard to know exactly what delta needs to be clamped at since i dunno what CHSV does with it
but you could try
int delta = NUM_COLS-col;
Earlier I suggested int delta = col; which should work, when combined with XY().
int delta = NUM_COLS -1 - col; should also work, it just goes the other way then.
yea basically the reverse
both of them gave me the "every second line reversed" (i gotta say, going from a simple 1 line neopixel strip to a matrix is hard)
What is your current code?
@lone ferry https://pastebin.com/yp7FQWqy
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.
Did you try leds[XY(col, row)] = CHSV(...) ?
I know, that's why I suggested it earlier.
now there is just the matter of the flickering -.-
i have a 500 resistor on the data line closest to the "first neopixel"
i fixed the flicker
did you turn off interrupts
i soldered 5v from the PSU and unplugged the USB powering the esp8266 ๐ works flawless
oh nice
do you have a cap between the + and - ?
if id have to guess, id say the usb power wasn't smooth enough
I have successfully got the Adafruit "sevenseg" demo running on my 1.2" 4-digit 7-segment display on an Arduino UNO. I am trying to get the same demo running on an ESP32 D32 Pro. ESP32 is 3.3V only so I have a separate 5V VCC running to the + on the I2C channel and 3.3V from the ESP32 to IO pin on 7seg. I have the SDA/SCL pins connected correctly. I am getting nothing from the display. I have GND on 7 seg connected to the 5V power GND pin. Does the ESP32 GND need to be connected to the same GND? Do I have to do something on the ESP to set GPIO21/GPIO22 to SDA/SCL or should they just work as I2C ports by default?
Here's a link to the pins for reference https://learn.adafruit.com/adafruit-led-backpack/1-2-inch-7-segment-backpack-arduino-wiring-and-setup
I have it:
C -> SCL
+ -> 5v
- -> GND
IO -> 3.3v```
Here is ESP32 D32 Pro pin layout
Yes, all the grounds need to be connected, since all the other voltages are relative to that.
I'm a little worried about the 3.3V logic, since the I2C bus is pulled up to 5V on the backpack.
Does the 1.2" backpack actually have an IO pin like you pasted above?
Oh, my bad, I was looking at the 1.2" 8x8.
There is the pin layout for this one @ https://learn.adafruit.com/adafruit-led-backpack/1-2-inch-7-segment-backpack-arduino-wiring-and-setup
Have you tried with only one display connected, to eliminate possibilities of address-pin problems?
There is no problem with address as I have them working independently using my UNO. I have the left one set to 0x70 and the right one set to 0x71
Any error messages from the code?
Double-check the wiring to 21/22... it looks like you might have the purple SCL wire going to SDA on 21.
If you run an i2c scanner on the ESP, does it see the two devices?
Where can I find an i2c scanner?
@cedar mountain You're right the 21/22 pins were the wrong way around. Unfortunately swapping them still doesn't light up the display
Thanks @north stream I'll take a look at that
The lack of errors is annoying, since it indicates the software isn't checking for anything. So, yeah, the scanner would be a good step to verify communications.
@lunar depot - can you double check the power (+/-) line connections on the breadboard - it is probably just the image paralax, but the ones on the right look, backward?!? and I can't really tell on the left
either that or perhaps the Adafruit write up lists the pins in the wrong order?
That's distinctly odd.
Something is unreliable. I tried a different breadboard. Maybe some of my jumpers are garbage
No I2C devices found
Scanning...
I2C device found at address 0x71 !
done
Scanning...
I2C device found at address 0x70 !
I2C device found at address 0x71 !
done
Scanning...
No I2C devices found
Scanning...
No I2C devices found
Scanning...
No I2C devices found
Scanning...
No I2C devices found
Scanning...
No I2C devices found```
Intermittent connections are frustrating
if its breadboard or EF wackiness, it sometimes helps for me to connect my IO lines to ground with a high resistance, like 500k when im proto boarding
It was just crappy breadboards. I changed to my good ones and it's all working now ๐
Never using crap breadboards again!
So everything is working great now, thanks to everyone who offered help!
Only have one minor issue now. I can light up the middle colon using matrix.drawColon(true). But how do I light up the front one?
I don't know offhand, but I'd look at the library to see what drawColon() does, and if there's something similar for the other segments/dots.
Just discovered that matrix.writeDigitRaw(2, 0x0E); lights up both
0x04 - left colon - lower dot
0x08 - left colon - upper dot
0x10 - decimal point```
Woot woot!
Wow nice!
Digital clock that displays milliseconds
When you boot up it connects to a time server to sync time
I am going to be adding a 32Khz crystal for keeping accurate time
Then 3d print a box for it
I'll be making all the code and files available on Github
Hmmmm.... I could use something like that to display timecode when I'm video editing....
@obtuse spruce code to display a timecode on two Adafruit 1.2" 4-digit 7-segment displays looks like this (start with the Adafruit "sevenseg" example):
{
int tm_cs = milliseconds / 10;
matrix1.writeDigitNum(0, timeInfo->tm_hour / 10, true);
matrix1.writeDigitNum(1, timeInfo->tm_hour % 10, true);
matrix1.writeDigitRaw(2, 0x02);
matrix1.writeDigitNum(3, timeInfo->tm_min / 10, true);
matrix1.writeDigitNum(4, timeInfo->tm_min % 10, true);
matrix2.writeDigitNum(0, timeInfo->tm_sec / 10, true);
matrix2.writeDigitNum(1, timeInfo->tm_sec % 10, true);
matrix2.writeDigitRaw(2, 0x0E);
matrix2.writeDigitNum(3, tm_cs / 10, true);
matrix2.writeDigitNum(4, tm_cs % 10, true);
matrix1.writeDisplay();
matrix2.writeDisplay();
}```
Resistance = (1023 / ADCvalue) - 1;
//Resistance = SERIESRESISTOR / Resistance;
what is this turning the analog value into?
some code notes:
int ms = millisconeds / 10 | 0;
The | 0 isn't doing anything. There is no need for it in C++ (looks like it was copied from Javascript).
The name ms is a bit misleading... perhaps cs for centiseconds
Since hours, minutes, seconds, and centiseconds are all less than 100, there is no need to '% 10' after the division by 10. Again, in C++, since these values are all some form of integer, the division will be an integer, and in these cases, less than 10.
@obtuse spruce You're right.. there is no remainder from an integer division. I lazily copied it from the Adafruit example. Anyway I've updated it now. Thanks for your input!
@mellow flax - it might be more clear if you think of it as 1023 * (1/ADCvalue) - 1?? You can really do that because this is all integer math... but it is equivalent to that.
@lunar depot Just call me "Dr. Code Hygene"!
And look how nice and clear that code looks now!
@obtuse spruce The joke is I'm normally just as pedantic but I was so caught up with my hardware issues I didn't even look much into it. But yeah it looks much cleaner now thanks again!
It looks great on these 7-segment displays too. They're super bright (brightness can be set between 0-15). I have it set to 4 and it's still quite bright.
I understand now
I wasn't fully understanding how the analog to digital conversion worked
Looks even better with the lights out!
I feel like that's a crazy amount of data lost during analog to digital conversion..
ADC values are always whole numbers right?
I'm sorry if this is a really dumb question, I don't even own an Arduino yet.
waiting for it to be delivered
I'm guessing the only way to avoid this would be to buy a thermistor with a less steep curve
Or add signal conditioning circuitry to match the range of interest to your ADC.
Uh Im in a class going over the basics of mircocontrollers, and I cant quite seem to get the homework right about Oms Voltages and Currents. Can Anyone Help me?
Probably, but you'll need to explain how far you've gotten and what you're unclear on.
it should work now
Create a new document and edit with others at the same time -- from your computer, phone or tablet. Get stuff done with or without an internet connection. Use Docs to edit Word files. Free from Google.
just started class today and its not really making sense
So, how far have you gotten and what are you unclear on?
so
it prompts
Draw the circuit for a 12V battery with a 2.0 Ohm resistor connected across it.
Draw the circuit in which the one above is altered to have a second resistor (of 4.0 Ohms) in series with R1.
Okay. Did the teacher explain series resistors?
Components in series are hooked end to end, so all the electricity flows through all of them.
ok
There's a nice writeup here https://www.electronics-tutorials.ws/resistor/res_3.html
okok
so
After that, it asks me the equivalent Resistor, in which I answered 6ohms
That seems right to me, resistors in series have their resistances added together.
And so how do I find V1, V2, I1 and I2?
that doesnt make sense to me
I know that V= IR
and the derivatives of that equation
and P=vi
Another thing about series components is that all the current flows through all of them.
So you've figured out the equivalent resistor, you can use that to calculate current, using the battery voltage.
so its 12V= IR
Correct.
and then just plug in the resistances?
You plug in that equivalent resistance you calculated earlier
Let's not worry about V1 and V2 yet, let's just figure out I to start with
okay, overall, its just just 2 and 6 right?
2*6= 12 so it makes sense reverse as well
It pays to be clear: 2 what, 6 what, and 12 what?
12v, 2A, 6ohms
Ah, much better.
Since all the current flows through all the series elements, you can deduce I1 and I2 fairly easily.
Both being 2A Correct?
Bingo, right.
Now there are two ways to calculate V1 and V2. One is to use V=IR again.
For each resistor, you know R and I, so you can calculate V.
V1 = 4
and V2 = 8
and it makes sense because adding them together makes 12
the total current right?
https://www.tinkercad.com/things/hXgXmgbBAHt Can anyone help me with that? I made it but after I press foward or backward button, the motor starts and the IR doesen't give me any other response
Total voltage, that is
right
All that looks good to me. However, there's another way to calculate V1 and V2, so you can do that too, as another cross-check.
Resistors in series are known as "voltage dividers", and the voltage divides proportionally by the resistance.
The voltage across each resistor is proportional to its resistance divided by the total resistance.
so because the proportion is 2:1, the remaining voltage would distribute as so?
not remaining
but all
Right. Or mathmatically, V1 = V * (R1 / (R1 + R2))
okay
finally
its asking me to do the same thing
but with series
sorry
not series
Parallel
Parallel works differently. In series, all the components get all the current, but the voltage divides. In parallel, all the components get all the voltage, but the current divides.
does this look like a good picture to visiualize?
Yes, looks a lot like the leading picture on the "resistors in parallel" page https://www.electronics-tutorials.ws/resistor/res_4.html
ooo
i remember seing something on khan academy on this
so the R123 would be like 1ohm
That's a good resource
Yes: they're all connected to the battery
Right. Then you can use Ohm's law to calculate the individual resistor currents.
so 6A, 3A, and 3A.
Also looks right. Do you know how to calculate the aggregate current from those?
(hint: it's not hard)
no clue what that is
The total current coming from the battery
12V
That's the voltage. You have the current through each resistor, all that is being supplied by the battery. So how do you get the total current from the individual currents?
Yes and yes.
For a check, since you calculated the equivalent resistance earlier, you can use that to calculate the current as well.
You have singlhandley in an hour taught me more than my Professor in 2 days in 1 hour.
You are a good man
I had teachers that seemed to make simple stuff confusing, I really try to avoid that, and I appreciate the compliment, thank you.
Now for @left grotto 's issue
hahahah thanks
I see the schematic, looks like an Arduino, IR receiver, motor driver, and two motors. You say "the IR doesn't give response", but I'm unclear on what that means, unless I'm misunderstanding something (likely)
after pressing foward or backward button and with the motors on, it doesn't get any signal
after that image i was pressing buttons of the control
I wonder if it's not getting signal, or the sketch has crashed
More specifically, I suspect the motors are introducing noise, spikes, and/or dips in the power supply, which could be causing the Arduino's CPU to glitch.
In general, electrically noisy things (like motors) shouldn't share a power supply with digital logic. This is one of the reasons the L293 has two Vcc pins, one for logic and one for the motor.
the motors make a noise but if i touch them so they start rotating, the noise stops
Interesting. That would seem to indicate the voltage is lower than the motors are designed for.
Not quite. You do want to connect the negative side of the battery to the 0V reference of everything else, but you do not want to connect the positive side of the battery to +5V
Basically, you only want to connect the positive side of the battery to Vcc2 on the L293 chip (pin 8), and disconnect pin 8 from everything else
like that?
Looks right to me.
didn't work, motors don't turn on
Hmm, do you know the ratings of the motors?
Hmm, 9V is high for those, I suspect they draw a fair amount of current, I wonder if it's more than the 9V battery can supply.
I think you are rigth. I connected arduino only to the battery and motors didn't turn on, so then connected the usb and they did
but it keep happening that after turning on the motors by the IR, it doesn't receive any signal
I suspect the IR receiver itself is getting the signal, but the Arduino has crashed and no longer responding to it. I would try adding some power supply decoupling/filtering to isolate the logic supply from the motor supply. If you have some capacitors, low value resistors, or diodes, it's worth trying a few configurations.
i have, but am really new to that, didn't know exactly how
I just found out that ultrasonic sensors dont work on non-perpendicular surfaces
would an infarred sensor work with nonperpendicular surfaces
I think that's not the issue
why does the serial thing hiccup like this
like its supposed to be the same thing before and after
but it isnt.
is this a problem with the serial?
heres tthe code tthat does that stuff
basically trying to run two roboclaws at once
Can someone help me with ttgo watch and displaying colors? I want to load bmp, but it displays wrong colors. So i decide to test it with manually entering r, g, b values - but it still display wrong colors. Here is my code:```cpp
for(int i = 0; i < ImageHeight; i++)
{
for(int j = 0; j < ImageWidth; j++)
{
LcdBuffer[j] = SmartWatch->tft->color565(255, 0, 255);
}
SmartWatch->tft->setAddrWindow(x, (ImageHeight-i)+(y-1), ImageWidth, 1);
SmartWatch->tft->pushPixels(LcdBuffer, ImageWidth);
}```Normally i read r, g, b values from bpm, but for testing i replaced it with 255, 0, 255 (this should be pink / magenta), but when i upload code to my watch it displays this:
What happens when you try (0, 255, 255)? @errant geode
@lone ferry Now it is yellow.
I try to load bmp image and invert colors ( SmartWatch->tft->setSwapBytes(); ) but still there is something wrong:
it seems like the display uses b, r, g format - magneta should be (255, 255, 0)
Indeed
Hi, I've got a question about my uno. I'm just lighting some LED's, however I'm getting a low voltage from every pin but the first of 3 LEDs (SOS example). All the LEDs work, all on 330 ohm resistors, and in just writing all pints high in the sketch, they work, but in the program the LEDs (2 and 3) are dim hence the low voltage. Thoughts?
How many LEDs do you have?
just one per pin, using 3 pins
@lone ferry @woven mica I tested all combinations and there is one good - this display is inverted bgr. Now it is working good, thanks for help ๐
@magic needle How have you connected everything?
pin# - jumper - led - resistor - gnd
Could you post a photo?
uploading, all resistors are in the same location, I'll post a third with all pins just written high
One thing that isn't immediately clear but does seem odd: is the - strip on the right side of the board actually connected to anything?
sorry, didn't realize I was missing that, yes it is, justjumped the +/- rails years ago, connection is fine, this issue just cropped up and I can't figure out why, hence my quesiton.
So the problem is that in the 2nd image the 3rd LED is very dim, but in the third image it works fine?
third image is just a separate sketch to make them all high for debugging, but the only thing that changes in the SOS sketch is the pin number just changing which LED is blinking the morse code
OK, so it looks like your pins and your LEDs work fine. The error must be in your SOS sketch then.
that's what I thought, but it was copy/paste, change the pin variable
Can you share the source code?
one sec, I think I figured it out, gimme a sec
HA! jumped the gun and I thought I had set my pinmodes, missed 2 and 3, makes sense now, but kinda strange that it still has an output when you don't set the pinmodes
There's old support for configuring a pull-up resistor on an input by setting it as an input and writing a high level to it: when I saw the dim LED, I wondered if I should point that out, but you seemed to be asking about something else.
There you go, mystery solved. ๐
heh, yeah, sometimes I can talk myself out of the problems. Thanks guys!
hey guys, complete noob here and I have a problem that's probably dumb easy. I have a green laser hooked up to my elegoo uno R3 but after 15 seconds the board get hot to the touch, the yellow light starts blinking and the laser starts flickering. Any ideas?
pretty basic setup, but I must be missing something
i think you need transistor and external power supply for laser
can you measure how many amps it uses?
Working Current:>200mA
arduino max 50mA per pin and total 200mA
you need transistor or relay to turn it on ๐
ahhh, I see. I have a PN2222, will that do the trick?
it's going to be a youtube tutorial day, I can feel it already haha
IC Collector Current 600 mA
i think just connect it to power supply and measure how much current laser uses
heeeelp :|
line
for (int i = 0; i < NUM_LEDS_PER_STRIP; i++)
error
comparison between signed and unsigned integer expressions [-Wsign-compare]
@elder hare I think it's saying that you didn't give "NUM_LEDS_PER_STRIP" a value
i have :S
the weird thing is
this code works on ESP32 but NOT ESP8266 :S
src\MyFastLED.h:253:5: required from 'MYFASTLED<PIN_OF_LED, NUM_LEDS>::MYFASTLED() [with unsigned int PIN_OF_LED = 22u; unsigned int NUM_LEDS = 19u]'
src\main.cpp:14:19: required from here
C:\Users\Krist\.platformio\lib\FastLED_ID126/fastpin.h:207:2: error: static assertion failed: Invalid pin specified
*** [.pio\build\esp12e\src\main.cpp.o] Error 1
Can someone help me with display... again? I have this code:cpp void DrawBmp(String Image, int x, int y) { File BmpImage = SPIFFS.open(Image); BmpImage.seek(0x12); int ImageWidth = BmpImage.read(); BmpImage.seek(0x16); int ImageHeight = BmpImage.read(); BmpImage.seek(0x36); uint8_t SdBuffer[720]; uint16_t LcdBuffer[240]; for(int i = 0; i < ImageHeight; i++) { BmpImage.read(SdBuffer, ImageWidth*3); for(int j = 0; j < ImageWidth; j++) { LcdBuffer[j] = SmartWatch->tft->color565(SdBuffer[(j*3)+2], SdBuffer[(j*3)+1], SdBuffer[j*3]); } SmartWatch->tft->setAddrWindow(x, (ImageHeight-i)+(y-1), ImageWidth, 1); SmartWatch->tft->pushColors(LcdBuffer, ImageWidth); } BmpImage.close(); }And this code works only with images that are 120x120px (my first image, logo) and 48x48px. Others resolutions are glitched, i dont know why? I tried 51x51 (dividable by 3), 54x54 (dividable by 9), even 81x81. Only working resolution i found so far is 48x48 (every image created and saved in microsoft paint, when i change resolution for example from 48 to 50 it glitches, when i switch from 50 back to 48 and upload it again it looks right again). This glitch look like this (clock is the only image with 48x48 resolution):
@errant geode - The reason is because each line of a BMP file is padded out to a multiple of four bytes. If your image is 51x51, then 51*3 = 153 bytes for the data - is going to be padded with 3 more bytes out to 156.
I assume you realize that you are making an assumption about the pixel depth of your images - rather than having the file tell you.... but that is reasonable if you know for sure they alwyas will be. Otherwise, that will, at some point that will bite you.
you mean, padded to 156
er, yes
The following addition to your loop should work:
int rowTail = ImageWidth*3 % 4;
int rowPadding = rowTail ? 4 - rowTail : 0;
for(int i = 0; i < ImageHeight; i++)
{
...
if (rowPadding)
{
BmpImage.read(SdBuffer, rowPadding);
}
}
@obtuse spruce Ok, thank you for help, I will try it.
ok.. i've got a weird issue i'm having with a pro micro..
i have a sketch that needs to able to operate as standalone, or output to serial if connected..
the issue is this: the "while (!Serial) ; loop ONLY succeeds after a flash.. if i just plug the device in after being powered down.. it never succeeds. the only way i can initiate serial communication is to reflash the sketch, and then it works as expected (but also can't operate in standalone mode as it's stuck in the while loop..
If you want it to be optional, while are you having the while loop be required? Also, just to double check, you are calling Serial.begin() before that while loop, yes?
yes, i'm calling serial.begin() -- it just will not open a connection, unless it has been run from a "warm boot" so to speak
i've even added delays and tried to rerun the function if (!Serial)
i can get it to run in either standalone or after a flash
it just will not open a serial connection in any scenario besides immediate after a flash
heck, it won't even reconnect if i pull RST low
in my core !Serial already calls a function with a delay... but maybe not yours....
maybe it's something about the bootloader i don't understand
so.. lets say for instance, i have an external power source.. but need to plug into a PC for datalogging via serial
how do i initiate that connection? Serial.begin only works after a flash/upload from what i'm seeing here..
Wait - are you include a baud value in begin()? Like
Serial.begin(115200);
yes
k
hang on let me get you a sample sketch illistrating the issue
No idea - it should work at any point, really
i guess i need someone to confirm that this doesn't work
it could be a bad 32u4 (although unlikely) -- i'll test with another
but let me bring my sample, to make sure i'm not overlooking something simple..
@obtuse spruce https://pastebin.com/EQZLY09H
tell me if you see anything that looks wrong there.. that demostrates and explains the issue
i mean, maybe i missed something...
Yeah, inside the whole loop you should have just:
if (Serial) break;
alright let me try that
in other words: if serial is up, we can stop waiting and checking.
yeah.. made no difference.. serial only starts after uploading.. if i unplug/replug the device, it never starts (and yes i have serial monitor open and connected to the proper port)
let me test it on another 32u4
yeah.. same.. it will not initiate the serial connection
Also... 9600? Usually my IDE picks a higher baud rate
it was just a a safe value.. i mean i doubt that is the issue.. we are just looking for serial at any speed..
9600 works after uploading just fine..
maybe it's something with the bootloader that it only initiates a serial connection after uploading for debugging?
It's just that uploading almost certainly uses a faster baud rate - and perhaps after uploading the Serial is left at that speed ... and if your IDE is using 115200, perhaps it works... and then when reset, the rate is reset to 9600... and if that were the case, the serial port won't connect, perhaps.... dunno.... this is Serial over a USB connection, right?
okay - I'm stumped! ๐ซ
it seems like 9600 isn't an issue
yeah me to.. it's caused A LOT of headache here..
from debugging interrupts, to debugging and testing i2c devices, to hours of playing with code to narrow it down to this
i thought my program was hanging
As a matter of fact, I can get it stuck in a state where I can't even upload a new sketch, just by using the while (!Serial) line
I have to pull reset low & pray my timing is good to reupload after that
so i guess i should file a bug report somewhere?
it seems that the serial protocol relies on some control signals that are (mishandled) at a lot of stages between programs & drivers on the PC side.
So when i upload somthing like the code below, it says i have not made a variable, even though i have. Its in the void start because if its made before randomSeed is called, it will just be the smae number everytime. Help? ```void setup(){
Serial.begn(9600);
randomSeed(analogRead(5));
int randomnumber = random(1, 9);
}
void loop(){
Serial.println(randomnumber);
}
so, upon uploading, the arduino IDE sets them properly (as they control RESET as well)
@main olive wrong scope.. you defined randomnumber in setup() but are trying to use it in loop
but it wont be affected by randomSeed if its above void setup
int randomnumber;
void setup() {
Serial.begn(9600);
randomSeed(analogRead(5));
randomnumber = random(1, 9);
}
void loop(){
Serial.println(randomnumber);
}
sorry that was quick and dirty let me look again
no that should work..
you are simply defining it as global (in my repost)
then initiating it in setup()
and reading it in loop()
ah
defining it globabally makes it usable anywhere. but you still have to write to it from inside a function
oh yeah. If i put it in void setup its a local variable and i cant access it outside of setup.
anyway, back to the serial thing.. so the IDE sets those lines, and resets it, leaving the serial port open.. otherwise a cold reset can't initiate the PC side of things, so you don't get a connected serial monitor...
maybe some different terminal software would fix this..
but it would still only work at the point of calling Serial.begin()
@main olive exactly
Ok... weirdly specific problem here. I'm making an Arduino proto-board setup with power and programming built in. I'm trying to figure out where to input power. 5V and USB-5V aren't connected, so if I was to connect to 5V would programming still work?
The source I'm using for power is the Adafruit PowerBoost 1000, so it outputs 5.2V.
The Arduino, if powered from the USB (as I understand it) would regulate this down, so I couldn't use it as a power source for the breadboard as the voltages wouldn't match.
@obtuse spruce yep.. changing the delay to 15 secs, and then manually reopening the serial monitor upon a cold boot fixes it.. sigh, what a crappy OS/software "design flaw" to work around
Is there any forseeable issue with connecting 5V straight to the breadboard and PowerBoost 1000?
guess i need to to randomly sprinkle some Serial.begin(0's in my code to enable it to be plugged in after the fact
and then wait for 500ms or so to see if it had serial initiated
I have never typed this, for SAMD21:
Wire.begin();
Might be an AVRism.
ISTR there was an #ifdef for that.
The Adafruit example code should run.
correction.. i don't need to do anything special.. Serial will set once it's ready (about 2 seconds) without a second Serial.begin statement..
so, i may just want to add a 5 second delay to allow the user to open a terminal program.. or not output anything until the datalogging process has begun..
I could not find the exact repository where the Arduino IDE draws from, for the gcc compiler it uses (wrt SAMD targets, anyway).
The version on my hard disk has an include file and I wanted the github repository source for it.
/path/to/files/.arduino15/packages/arduino/tools/arm-none-eabi-gcc
$ egrep int64_t stdint-gcc.h
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
$ pwd
/path/to/files/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/lib/gcc/arm-none-eabi/7.2.1/include
One of the programs I use (YAFFA-ARM) makes use of these types; I could find no reference to them outside of the compiler itself.
Hey folks. I just got a new Feather Huzzah and I'm trying to upload a sketch, but the upload always fails with this rather unhelpful error: Connecting....
A fatal error occurred: Timed out waiting for packet header
@pine bramble - those __INT64_TYPE__ etc. are predefined by the compiler itself: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
Common Predefined Macros (The C Preprocessor)
These are very specific to GCC, and I can't imagine that any library should be using them directly.
Wait, are you referring to int64_t and friends? Those are part of the C++ standard, and you get by including stdint or stdint.h (your pick...)
Looking at the source for YAFFA-ARM, it seems that YAFFA.h isn't self contained: It relies on includes that the includer of YAFFA.h must have included first. YAFFA-ARM.ino doesn't include any standard headers, and indeed won't compile on my system.
If, however, you include Arduino.h before you include YAFFA.h things will work, because you get stdint.h indirectly when you include Arduino.h
@topaz compass Arduino doesn't seem to see the Feather. What's your hardware setup, and can you verify the Port choice in Arduino matches the USB port it's on? Does the PC see the device on the USB port?
It looks like the PC sees it just fine:
And yes, I verified the port chosen in Arduino is COM4
@obtuse spruce Thanks!
YAFFA-ARM is upstream (and it's been so long I don't remember if it compiles with no prep).
https://github.com/wa1tnr/ainsuForth-gen-exp-m4
is my go-to port of YAFFA-ARM. I haven't looked at it in quite a while, as it was more interesting to me before I found an eForth port that ran on an Adafruit target (STM32F405 Express).
https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
There was a copy of this in my Arduino IDE tree and I looked at it this morning.
All my programs (almost all of 'em anyway) have a blank .ino (or just comments) and (therefore) must
#include <Arduino.h>``` .. in the `.cpp` file(s); otherwise they don't compile. I had no real idea what is included when that one is. ;)
I found (through experimentation) that a directory named ./src is treated as expected.
No other name is recognized - haven't figured out where this is implemented.
I have MCP23017 module and nodemcu. I'm trying to use interruptions of MCP to know about buttons clicks, but they just not work. I need help with it.
https://hastebin.com/narecukehu.cpp
@alpine oasis No Arduino IDE compile errors?
just making sure
You could do a simple code test just to report back the levels of the buttons (without the complexity of the interrupts) to verify wiring and that all the parts in the path function. I see an LED and resistor, so I'm guessing you've checked the button functions all by itself as wired.
I had ticker outputting values from mcp row. Checked that buttons properly connected. After it commented.
So buttons work.
Resistor and led not connected. Left for debug.
it's possible to compress an arduino code ?
Oh that is quite a rabbit hole, practically and easily, no, but there is a lot you can do to conserve memory
Self compressing code is actually a thing, you mean in order to execute correct?
I have installed an arduino in my video game controller, but the arduino code i put takes 18% of the space and the bigger the data, the more delay there is
That is not correct, but I think I know what you are meaning, bigger applications do not cause a longer "disk" time. I think you might need to look at how your code is laid out, if you put it in a paste bin I can take a look at it
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.
Why is your code like... so tightly written? Nothing really wrong with it but it does make it harder to read
Also, which Arduino are you using? Storage space is not your issue, and Im not seeing much in the code that is blocking. And how long does it take to loop through main once?
I use Arduino Nano
How long does it take to go through the main loop once? And what is appearing slow to you?
if I only leave the minimum in the arduino, it seems faster to me
I dont understand what you mean by that
Like I said before, when my arduino have 18% of data , I felt not faster than if he have 4%
The issue is not the code size, but rather the code that is included within that extra 14%. What are you removing/adding from the code
I didn't removing adding from this code
What did you do to go from 4% to 16% storage usage?
oh, I delet somes Lines of the code yeah sorry
Which lines?
from void perfectangles(){ to void nocode
But you are still running controller.read(); gcc = controller.getReport();?
yeah
Okay, if so, I think the nano is having an issue keeping up with the math if Im not mistaken
Could you tell me how long it takes to execute convertinputs()?
how I can know that ?
First you would need to start a serial connection to your computer by adding Serial.begin(115200); in setup so you can see the result. Then you can run within your main loop-
unsigned long s = micros();
convertinputs();
Serial.println(micros-s);
So I plug my arduino in the computeur, then with the software Arduino ? I have to do what ?
In the upper right there is a button with a looking glass and when you hover over it the words Serial monitor should appear
true
I past this : "Serial.begin(115200);"
nothing happen when I sent "Serial.begin(115200);"
You need to add that to your code in the setup section
No, that code you need to add to your code within the main loop, that serial monitor will show you whats put in Serial.println(micros-s); when ran
I really don't understand
I plug my arduino nano in my computeur
then I click in the monitor , I can send a line
The code is not setup to receive the line, it will print in the box below the output of the Serial.println(); line
Put it in the setup function inside the code, yes
No, put it in the setup function
No, in the setup function, like this-
void setup(){
Serial.begin(115200);
gcc.origin=0; gcc.errlatch=0; gcc.high1=0; gcc.errstat=0; //init values
swang = ang(abs(sw_notch_x_value), abs(sw_notch_y_value)); //calculates angle of SW gate based on user inputted data
seang = ang(abs(se_notch_x_value), abs(se_notch_y_value)); //calculates angle of SE gate based on user inputted data
}
Awesome, great, then add the other code I gave you to your main loop
Yeah, that should work. Go ahead and upload the code, then open the serial monitor, then in the lower right of the serial monitor there is a drop down and select 115200
My bad, forgot the (), please fix that last line in loop Serial.println(micros()-s);
still nothing
But the code is still working as ususal?
yes
And you have the correct serial port selected?
yes
Could you pastebin your code again for me? That should be working
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.
Im not sure, are you sure it uploaded to the arduino correctly?
All good
Alright, so that is only taking 28 microseconds max, that is not the issue, I have a feeling it is the reading and writing causing the issue. Go ahead and put the code back to the way you had it
Let me write you a bit of code to use instead actually, hold on
it is possible to add a setup for faster read / write ?
That is in the library you are using, it would require a lot of work. Hold on and we can verify what is taking a lot of time to execute
Here, please try this code and show me what prints to serial- https://pastebin.com/TEBNcgqx
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.
If there is a compiler error let me know
thx
Did you get that uploaded?
I will (I am slow)
Okay, no rush, you might have to @ me when youre done to get my attention
Okay, so each loop is taking around 1488us to execute, which means your loop is updating 67 times per second, from what I know about controllers that isnt very slow
it is not possible to decrease this latency time?
what you added did not decrease the latency time?
What I did will increase it slightly but most of the time in the program is spent reading the controller which is a part of the library you are using
My code just adds a output so you can see where time is being spent
But it is not very much latency
Oh there is also a line of your old code missing, hold on
wish part ?
https://pastebin.com/RY5LQ4q9 Could you try this? I think this will give us a slightly better picture
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 missed the console.write(gcc);
@stuck coral & @formal python - you're off by a factor of 10. The loop is running 670x a second
So... skimming back through this thread.... I feel like I don't understand what problem this speeding up is trying to affect? Updating 600+ a second, if this is something about human perception - it isn't going to make a difference if it is 300x or 1200x.... that is all faster than eyes/ears/hands perceive
If it's running at 670 Hz you could toggle a GPIO pin attached to a piezo buzzer and hear it for yourself.
I agree with @obtuse spruce I dont think the arduino is introducing latency
If it was polling at 67 times a second and I forgot a write command sure, but not 670
What does that get us @pine bramble?
Just a sanity check. Reinforces what the true loop speed could be.
(an oscilloscope would be better)
Well lets assume the hardware does not have some absolutly critical issue... that is out of the scope of the latency issue
Otherwise you wouldnt be able to read the controller
I'd like to see the library code that supplies CGamecubeController and CGamecubeConsole
Ive got it hold on
anyone have the link?
However, as printing the micros values shows, the reads are taking just over a ms. Idk about writes and Id like to see that but I dont see an issue https://github.com/NicoHood/Nintendo
The timer is not being messed with
@formal python when you tried the code I just sent you, were you sure to copy and paste the entire thing?
Because the variable is within the scope
yes
Im looking at my code, and its written right, startWrite is defined and within the scope
Alright, can I see serial so we know how long writes are taking?
only odd thing I see in that library is that it turns interrupts off during I/O with what I assume is "the old way" of turning off interrupts?
uint8_t oldSREG = SREG;
cli();
Oh yes, you are correct
So we cannot rely on micros
We're not using other inturrupts, could we just remove that line for now?
oh my - the library is doing bit banging Serial... coded with inline assembly.... carefully tuned to only work on a 16MHz processor (though one wonders if that is enough of a test....)
;)
But no matter - the code is reading and writing the correct values, right @formal python ?
So, @formal python - what is the issue you are seeing when using this code that makes you think it is slow?
Okay @pine bramble I get it ๐ I owe u a shot. what were the chances he had a piezo anyways
The only thing I have to go on is - "if I only leave the minimum in the arduino, it seems faster to me" --- can you explain what feels faster, and how much?
Was a good call
My bad swap convertStart in that line for startConvert
@obtuse spruce yes , I feel latency
Well from what you told me, the code you added is not adding much latency, its the reads and writes that are taking time
@stuck coral Was just trying to contribute in a sciency way. ;)
@obtuse spruce what would you think about disabling the IRQ just for now to get some basic timing info even if it doesnt read right?
And off I forgot the println, but writes are supposively taking the longest
yes it is really at the level of the use that I feel the latency, the general use of the controller
What is this outputting to?
you talk to me ? about the screen I sharing ?
What is the arduino outputting to? I get the controller is an input
to fixe controller
So this is going into a game cube?
bad protocol
i keep the code like you put on pastebin in my arduino?
The latency comes from the contents of the program, not its execution. /guess
Well its coming from the library for sure, the reads and writes
As mzero points out, IRQs are being disabled, and as you point out, bad protocol
The upstream author may not have worked out all the problems to bring this out of 'demo' and into 'hot rodded' level of performance.
@formal python - I suggest you do two things:
- Back out the timing code above - as it will induce latency (printing to Serial takes time) - and put in code that only prints out total loops per second every few seconds. I have code for you if you want.
- Change the code for
nocodeso that you can toggle the code off and then back on. It is important to see the effect of the latency with and without the code immediately, not with a stop and upload cycle.
Could be a reverse-engineering guessjob. ;)
Agreed @formal python should swap back, I was just using serial for some figures.
I don't think the library is the issue - that looks reasonable from my quick glance... and certainly isn't going to cause latency or not based on the computation in convertInputs
Well its not in anything in the main sketch
Use this for loop():
void loop(){
controller.read();
gcc = controller.getReport();
if (!off) {
ax = gcc.xAxis -128; ay = gcc.yAxis -128; //offsets from nuetral position of analog stick
cx = gcc.cxAxis-128; cy = gcc.cyAxis-128; //offsets from nuetral position of c stick
axm = abs(ax); aym = abs(ay); //magnitude of analog stick offsets
cxm = abs(cx); cym = abs(cy); //magnitude of c stick offsets
convertinputs(); //implements all the fixes (remove this line to unmod the controller)
}
console.write(gcc);
static int loopCount = 0;
const unsigned long reportPeriod = 5000;
static unsigned long reportTime = millis() + reportPeriod;
loopCount += 1;
if (millis() > reportTime) {
Serial.print("in ");
Serial.print(reportPeriod);
Serial.print('ms, rean ');
Serial.print(loopCount);
Serial.println(" loops.");
loopCount = 0;
reportTime = millis() + reportPeriod;
}
}
That will print out the number of loops exectued in each 5 second period.
D'oh - I fixed it a little bit more - we want it doing nothing but reading and writing when "off"
Now - the code for toggling it on or off needs to be made to toggle... hold on....
I waiting thx
I think this will work:
void nocode() {
static bool heldDown = false;
static bool waiting = false;
static unsigned long toggleTime = 0;
const unsigned long toggleHoldTime = 2000;
if(gcc.dleft) {
if (!heldDown) {
toggleTime = millis() + toggleHoldTime;
helddown = true;
waiting = true;
return;
}
if (waiting && millis() > toggleTime) {
off = ! off;
Serial.print("input conversion is now ");
Serial.println(off ? "off" : "on");
waiting = false;
}
}
else {
heldDown = false;
waiting = false;
}
}
That will let you toggle the conversion code on or off by holding d-left down for 2 seconds
Oh - foo!
that code is called only IN convertInputs()
so - take this line out of there:
nocode(); //function to disable all code if dpad left is held for 10 seconds
and move that line to just after console.write(gcc); in loop()
'k?
so I replace the :
void nocode(){
if(gcc.dleft){
if(n == 0) n = millis();
off = off||(millis()-n>2000);
}else n = 0;
}
with the new ?
yup
yes and yes
I don't understand, I have to correct something ?
look at the line in error... look at the variable that it says wasn't declared. Look up a few lines, you'll see it was decalred .... but spelt with a capital D in the middle: heldDown
then fix the line that is red.
okay
SO
NOW
you should see, every 5 seconds it printing out a loop count
AND... if you hold d-left down for 2 seconds, you'll see it toggle off / on the extra code you suspect is causing lag
while it is off ... you'll see the loop count ... and can compare that to the loop count when on
this gives you a measurement - how much difference is there?
You can also use the system - play some game - and compare the feel with it toggled on -- and toggled off ---- even better - get a friend to toggle it on or off randomly .... then play back and forth and see if you can guess which what it is!
BUT - for all of us here.. what numbers are you seeing?
yeah - are they scrolling by?
We don't need a picture - just tell us the number of loops in 5000ms
about one line per 5 seconds is what you should be seeing
Reposting my previous plea for assistance...Hey folks. I just got a new Feather Huzzah and I'm trying to upload a sketch, but the upload always fails with this rather unhelpful error: Connecting....
A fatal error occurred: Timed out waiting for packet header
@topaz compass I had that issue for a while using a front panel desktop USB that wasnt great, I would check the cable and try another USB port, if that does not work if the feather is in a socket remove it.
Thanks. Will attempt that now...
@obtuse spruce for that I have to add Serial.begin(115200); right ?
I told him to swap my code back, it wasnt there to start
Same result. Additional information: after the failed upload, the on-board LED goes solid bright red and stays there.
Do you have a bunch of stuff connected to it?
Just one thing. A STEMMA temperature sensor. Think removing it could help?
Try just the HUZZAH by itself
Ok. Doing that
Desk of LadyAda was (still is?) on; lead piece was a nice bit about reverse engineering using the USART.
plate o' shrimp
Still no luck
Hm, that message means the GPIO0 pin or another boot pin isnt in its correct state, or there is a bad USB connection
with the new voidloop when I try to add :
unsigned long s = micros();
convertinputs();
Serial.println(micros-s);
I got no matching function for call to 'println(long unsigned int (*)())'
Swap that with Serial.println(micros()-s); @formal python
oh yes
BUT - if you add that code you will totally throw the timing of loops per interval off : Serial.print takes significant time
It is fine for measuring just one thing --- but you can't use it for finding out how fast the code as a whole is --- we are trying to establish that loop() will execute in the 100s a second - and pretty much the same wether conversion is toggled on or off
BUT - for all of us here.. what numbers are you seeing?
@obtuse spruce
so you don't talk about Serial.println(micros()-s); ?
no
Interesting? info from "Get Board Info" : BN: Unknown board
VID: 10C4
PID: EA60
SN: Upload any sketch to obtain it
Doesnt really tell you anything
In the code I gave you - every 5 seconds (if I coded it right ๐ ) - it will print out a line like:
in 5000ms, ran 3134 loops
in the serial monitor right ?
where I can see "in 5000ms, ran 3134 loops" ? in the serial monitor nothing happen
should be there - once every 5s
do you see the code that would write this line - at the end of your loop() code?
loopCount += 1;
if (millis() > reportTime) {
Serial.print("in ");
Serial.print(reportPeriod);
Serial.print('ms, rean ');
Serial.print(loopCount);
Serial.println(" loops.");
loopCount = 0;
reportTime = millis() + reportPeriod;
}
}
that's the code - should be running every 5 seconds.... You did copy-n-paste my code, right?
;)
I do
Use this for
loop():void loop(){ controller.read(); gcc = controller.getReport(); if (!off) { ax = gcc.xAxis -128; ay = gcc.yAxis -128; //offsets from nuetral position of analog stick cx = gcc.cxAxis-128; cy = gcc.cyAxis-128; //offsets from nuetral position of c stick axm = abs(ax); aym = abs(ay); //magnitude of analog stick offsets cxm = abs(cx); cym = abs(cy); //magnitude of c stick offsets convertinputs(); //implements all the fixes (remove this line to unmod the controller) } console.write(gcc); static int loopCount = 0; const unsigned long reportPeriod = 5000; static unsigned long reportTime = millis() + reportPeriod; loopCount += 1; if (millis() > reportTime) { Serial.print("in "); Serial.print(reportPeriod); Serial.print('ms, rean '); Serial.print(loopCount); Serial.println(" loops."); loopCount = 0; reportTime = millis() + reportPeriod; } }
@obtuse spruce
I replaced the old void loop with this void loop
@stuck coral & @pine bramble - wanna eyeball that for me.... I think I got the code right
And you do have Serial.begin(115200); in setup(), right?
yes
they are static
Yep nevermind, looks good to me
loves static variables
I dislike them, the C++ syntax makes it hard to read because it makes it seem that the initializer is always being set
Well, not hard but can trip me up
True, but the benefit of being close the point of usage, and name scoped out of the way of everything else is VERY VERY big.
@formal python - Try adding this line just after console.write(gcc)::
Serial.println("hi");
Serial.print('ms, rean ');
```Not sure what the single quotes are doing.
I agree with @pine bramble the single quotes is incorrect, but it should still be printing something in the if statement
I just don't know what a multiple char '\n' utterance is.
There was a discussion about it; I believe it's legal C.
I would like to hear it but I have seen it used and also believe its legal
Not sure why or how, maybe compiler voodoo
It made sense -- I just don't remember the punch line. ;)
Oh because a /n is a ASCII newline if I remember right 0x0a.... might be wrong on that
Because you can have in a text document the chars \n and it wont display a newline
(sorry - was on a plum torte dessert break)
So - okay --- @formal python -- take out the "hi" line you added, and fix this line I mis-typed:
Serial.print("ms, ran ");
notice that it changed from single quotes to double quotes.
good eye, @pine bramble
Would that cause nothing to be printed? Im amazed
in setup void right?
no - that is in loop()
just after the line " console.write(gcc);" right?
@stuck coral since ' is for a single char maybe it just printed the last space
char lit
@obtuse spruce nothing happen
if you replace the if line:
if (millis() >= reportTime) {
with
if (true) {
does it print then?
please cut-n-past the code for loop() as it now stands?
fades .. ร bientรดt.
@obtuse spruce where do you see the code for loop ?
the entire void loop(){ ... } function, all the code it runs in the main loop
ok.. i'm getting really frustrated with these adafruit libs..
i've been having problems for 12 hours with a pro micro, sdcard module, and SSD1306 oled module
I just realized what is actually happening... it's out of ram.. which i'm not sure how that isn't caught somewhere in code.. i mean shouldn't a malloc() fail somewhere, instead of allocating more ram than what is available?
^ but that's an arduino thing
however.. the adafruit SSD1306 libs return valid upon Display.begin() -- EVEN WHEN NO DISPLAY IS PRESENT...
and still takes up the same amount of memory, and causes everything to not work as intended..
I mean.. if there is nothing on the i2c bus.. shouldn't it return something other than successful?
sorry---done
Use this for
loop():void loop(){ controller.read(); gcc = controller.getReport(); if (!off) { ax = gcc.xAxis -128; ay = gcc.yAxis -128; //offsets from nuetral position of analog stick cx = gcc.cxAxis-128; cy = gcc.cyAxis-128; //offsets from nuetral position of c stick axm = abs(ax); aym = abs(ay); //magnitude of analog stick offsets cxm = abs(cx); cym = abs(cy); //magnitude of c stick offsets convertinputs(); //implements all the fixes (remove this line to unmod the controller) } console.write(gcc); static int loopCount = 0; const unsigned long reportPeriod = 5000; static unsigned long reportTime = millis() + reportPeriod; loopCount += 1; if (millis() > reportTime) { Serial.print("in "); Serial.print(reportPeriod); Serial.print('ms, rean '); Serial.print(loopCount); Serial.println(" loops."); loopCount = 0; reportTime = millis() + reportPeriod; } }
@obtuse spruce
here
very quick question, it is possible to disable the internal led of the arduino with coding ?
not the power LED, no
Quick question, if I'm using an esp8266 and the 12,13, and 14 pins are take, what pin should I use for a tilt switch?
This is on a feather Huzzah
I was thinking 16 but it isn't working how I thought so I think i may have goofed in my pin selection
Are you using 16 for the special deep-sleep wakeup function, or just as a regular GPIO?
Hey if anyone is around and has a few, I'd like understand rotary encoders a bit. I just received a set of encoders and all 5 of them set up seem to give inconsistent data when turning the dials in any direction. Beating my head on it for a couple of hours now
Are they quadrature encoders, or few-bit position encoders?
I've gone through quite a few examples and this is the last one I've used:
static int LastState;
int Clock;
if(LastState == (Clock = digitalRead(altitudeClockPin))) return; // No Change
LastState = Clock;
if(Clock == 0) return; // Clock Went Low
//Clock went High
if (current - lastAltitudeRotaryDial > 100)
{
(digitalRead(altitudeDataPin))? Serial.println("ALTITUDE_UP"): Serial.println("ALTITUDE_DOWN");
lastAltitudeRotaryDial = current;
}```
Gotcha. It looks like they're calling CLK and DT the usual quadrature encoder A and B signals.
Yea, that is what I have read
this is the funkiest example I've used so far, lol. I've tried the other more basic ones as well. I just find it odd that all 5 dials are outputting to me the same (I have only switched them out from the same circuit)
It's not obvious to me how the code works. The fact that it's updating the state from A all the time but only looking at B with a millis() delay seems to indicate that you might be missing some transitions.
I'll show you another example I have used, with same results
What sort of results are you seeing?
basically no matter the direction i turn the dial, I am getting a mix of the Serial.println("ALTITUDE_UP"): Serial.println("ALTITUDE_DOWN");
int current = millis();
if (rotaryCurrentClock != altitudeClockLast && (current - lastAltitudeRotaryDial > 500))
{
if (digitalRead(altitudeDataPin) != rotaryCurrentClock)
{
Serial.println("ALTITUDE_DOWN");
}
else
{
Serial.println("ALTITUDE_UP");
}
lastAltitudeRotaryDial = current;
}
altitudeClockLast = rotaryCurrentClock;```
never mind the 500 , its just the latest tinker to it
even at that amount of debounce, i still get a mix of outputs
that is just on turning it clockwise
rotary encoder and debouncing?
its the same without it
Gotcha. I'm still a bit confused by the algorithm, so I'd just advise doing more of a classic A/B state machine approach.
I have tried that code as well ๐ฆ
the simplified example one
and the interrupt example
. @cedar mountain regular gpio!
I've just now tried this from the simplified example again:
if ((altitudeClockLast == LOW) && (rotaryCurrentClock == HIGH)) {
if (digitalRead(altitudeDataPin) == LOW) {
Serial.println("ALTITUDE_UP");
} else {
Serial.println("ALTITUDE_DOWN");
}
}
altitudeClockLast = rotaryCurrentClock;```
no matter which direction, it is printing ALTITUDE_DOWN at least 90% of the time
no debounce
@sinful nimbus What problem are you seeing?
Here i posted on the forums, https://forums.adafruit.com/viewtopic.php?f=8&t=169198
I apologize if I randomly disappear, it's almost 3 a.m. here my wife will be mad if I stay up at me later
But basically the Tilt switch will activate but then it won't go back to its previous state
digitalWrite(inPin, HIGH); // turn on the built in pull-up resistor
i am not sure about this
And I'm sure there must be something that I'm doing wrong on the software side. I tested the switch with a multimeter and it seems to be okay
time =r millis(); is that a typo, or is that in your code
Typo
k ๐
what if you try pinMode(inPin, INPUT_PULLUP)
I've actually tried that. That's actually the original code that I was testing it on
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.
og code
When that didn't work I decided to just go to a very simple example, to see if there was something weird
I also tested the switch with a multimeter and it seems to work fine
attachInterupt( what types are these here? )
?
I find that if I turn through the detents very slowly, I get my desired output. But any sort of rotation faster, even if I still just go detent to detent, I get my usual mix of outputs.
I was finally able to find some code that solves it
static int8_t rot_enc_table[] = {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0};
prevNextCode <<= 2;
if (digitalRead(altitudeClockPin))
prevNextCode |= 0x02;
if (digitalRead(altitudeDataPin))
prevNextCode |= 0x01;
prevNextCode &= 0x0f;
// If valid then store as 16 bit data.
if (rot_enc_table[prevNextCode])
{
store <<= 4;
store |= prevNextCode;
if ((store & 0xff) == 0x2b)
{
val = -1;
}
if ((store & 0xff) == 0x17)
{
val = 1;
}
}
else {
val = 0;
}
if (val)
{
if (prevNextCode == 0x0b)
{
Serial.println(commandUp);
}
if (prevNextCode == 0x07)
{
Serial.println(commandDown);
}
}```
O_o
Rotary Encoder
https://github.com/mathertel/RotaryEncoder
โพ
https://github.com/mathertel/RotaryEncoder/blob/master/RotaryEncoder.cpp#L20 says:
const int8_t KNOBDIR[] = {
0, -1, 1, 0,
1, 0, 0, -1,
-1, 0, 0, 1,
0, 1, -1, 0
};
That seems to be the essence of quadrature encoding.
Rotary Encoder question, arduino.cc forum, March 2016:
http://forum.arduino.cc/index.php?topic=389243.0
I have unpublished working code for an Arduino SAMD21 project that does rotary encoder.
It's definitely sensitive to the speed of rotation - no doubt at all.
If you want to slew rapidly, it can do that, but it's calibrated within a fairly narrow range of rates-of-turn. (or RPM).
๐น
I needed nimble accuracy at slow turning rates (to select menu items displayed on an LCD, by turning the rotary encoder and using its inbuilt switch).
Pressing the switch (end of encoder shaft) makes the selection known to the microcontroller.
Faster turning rates dropped clicks (encoder detent crossings).
// mirror symmetry ... or palindrome
const int8_t KNOBDIR[] = {
0, -1, 1, 0, 1, 0, 0, -1,
-1, 0, 0, 1, 0, 1, -1, 0
};
Question, i removed these to make the 8x8 flush with the board and the rest of the matrix! Question is the chip (GC7219C 1906+) will it get to hot? Now that the matrix is that close to it?
I doubt the matrix is dissipating enough heat to be an issue.
never buying from banggood again -.- bad PCB -.- the solder pads went right off
I get an error when i upload my code saying that it cant connect to my arduino even though it is plugged into my computer. code: https://hastebin.com/emakaworot.cpp
That is not an issue with the code
oh
@main olive You can capture the error using your mouse.
I would try another cable or USB port first, which OS are you on?
windows.
Swipe the orange text and copy it (control c) to the clipboard, then paste it somewhere.
Could be very long text so maybe pastebin.
Ah, I thought it was the error I saw earlier, so that is a code issue
There should be dozens or hundreds of lines of text.
There is no main loop
Arduino IDE, lower half of the window.
Arduino requires a loop(){} to be defined
If there's no loop then everything I said does not yet apply.
You can have an empty loop, when all your code is in setup().
When it gets to loop(); it just loops infinitely.
I have an external 12v battery with 2.4amps. Is it bad to have 2amps being fed into my Arduino uno? It gets really hot and auto shuts off after 5 seconds of running. I have a 5v stepper and a 3.3v laser running (200ma). It works find if the laser isnt hooked up.
@deep salmon 12v sounds high for the Uno. What's the spec for it say?
200 mA may be a bit much at 3.3 V. I didn't know the Uno had a 3.3V output.
it's a knock-off board tho
I'm using the 5v to power both the stepper and the laser. I use a buck converter to drop the voltage down to 3.3 for the laser
Try running everything as a stress test, except disconnect the laser. You probably have found the voltage regulator IC which is usually the part that gets hot when there's too much current drawn.
If anything is too hot to touch shut it all down immediately. ;)
And if it got that hot, don't retry the same thing immediately; needs time to cool down.
yep, when I disconnect the laser it runs fine for a long time. With the laser it gets super hot, right next to the barrel connector port after 5 seconds
Right, so don't do that anymore.
You're not going to get a different answer the seventh time you try it. ;)
Be extra careful with the laser, it may be a dead short.
(zero ohms)
repairfaq.org has troubleshooting tips.
(which is also the site of Sam's Laser FAQ btw)
Heh, was just looking at that site.
;) Yeah I read it in depth about 10 years ago.
That's probably about the time I bought this yellow laser tube.
And you can still see out of both eyes, huh. ;)
I play with lasers, fireworks, and high voltage and I'm still alive and have both eyes and all my fingers and toes. My hearing, however, isn't so great.
anyone ever try to make the adafruit ssd1306 lib work on an stm?..
Then I'd imagine that the Adafruit_ssd1306 should work just fine, @wooden crescent
If you can build and run an Arduino sketch on the STM32F405 Express, that's the hard part of the learning curve. That first working sketch you wrote (or just uploaded).
After that the differences between STM32F405 Express and other Arduino target boards aren't as important.
That's the entire point of the Arduino ecosystem. ;)
The Amazon Basics Micro B cable should work for serial connection right?
for some reason none of the cables I already own are working
You are trying to establish a serial connection over USB to a board with a USB micro connector using arduino?
yes
What OS are you using?
windows
They're going to be selling those to anyone who wants to side-load onto a cell phone, a Kindle and whatnot.
You should have several USB cables to try.
yea I have more coming in the mail tomorrow
Is the board getting powered @mellow flax?
yes
I should be clear that I haven't tried the amazon basic cable yet
its being delivered tomorrow
Ah, lets try that then report back
Yeah, dont get a charge only cable
Whoever came up with 'charge only cable' needs to go to the Special Place.
If you happen upon a charge-only cable, you can cut it in half with scissors. Failing that, tie a knot in it.
I agree
I like the USB-A to 2.1 mm barrel plug because .. hey .. barrel plug.
No confusion there. ;)
How can I build a circuit for multiple stepper motors?
You can either use H-bridge chips and control them directly, or use stepper motor control chips and send them commands.
I'm using DRV8825s
The way it rn is that the Arduino is plugged into a Pi and the Pi picks which motor to move and how many steps through serial commands
The first motor (the druver on the far left) is very smooth and works perfectly
The second motor (the driver in the middle) moves at a snail's pace and moves in small step increments
Is it because the capacitor for the first driver is stealing away the current from the second driver and it diminishes down the rail?
How can I make sure they get equal power?
Hmm, those are fairly basic controllers, they have enable, direction, and step inputs. I would guess a power supply issue or a problem with the Arduino code.
hmm
I'd probably try swapping the signals from the Arduino to the first two drivers and see if the problem moves. If so, it's more likely an Arduino problem. If it doesn't, it's more likely a wiring/power problem.
Yes, take the signals connected the left driver and swap them with the signals connected to the middle driver.
It might be an Arduino problem
Whatever is "motor A" (pins 2 and 3) in the code works well and whatever is "motor B" (pins 4 and 5) in the code stalls
That's a useful clue.
I'm using AccelStepper
That's normally a pretty solid library. I wonder if it's getting interrupts that keep it from finishing, or there's something odd about those pins, or what.
Maybe my code is just terrible xD
#include <AccelStepper.h>
#define dirPin 2
#define stepPin 3
#define dirPin2 4
#define stepPin2 5
#define motorInterfaceType 1
int SPEED=200;
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
AccelStepper stepper2 = AccelStepper(motorInterfaceType, stepPin2, dirPin2);
//Steps the motor
// Stepper object, number of steps, previous position of stepper motor
void stepMotor(AccelStepper myMotor, String motorSteps, long int previousPosition){
while (myMotor.currentPosition() != previousPosition+motorSteps.toInt()){
if (motorSteps.toInt()<0){
myMotor.setSpeed(-SPEED);
} else {
myMotor.setSpeed(SPEED);
}
myMotor.runSpeed();
}
}
void setup()
{
//Open serial communication
Serial.begin(9600);
// Setting the positions and max speeds of the two steppers
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(1000);
stepper2.setCurrentPosition(0);
stepper.setMaxSpeed(1000);
}
void loop() {
long int prevPos=stepper.currentPosition();
long int prevPos2=stepper2.currentPosition();
String motor="";
//Stalls the program until new serial data comes in
while (Serial.available()<=0){}
if (Serial.available() > 0) {
motor = Serial.readStringUntil('\n');
Serial.println(motor);
if (motor=="A" || motor=="B") {
Serial.println("Motor received.");
}
}
//Motor end
//Stalls the program until new serial data comes in
while (Serial.available()<=0){}
if (Serial.available() > 0) {
String steps = Serial.readStringUntil('\n');
Serial.println(steps);
if(motor=="A"){
stepMotor(stepper, steps, prevPos);
} else if (motor=="B"){
stepMotor(stepper2, steps, prevPos2);
}
}
//Steps end
Serial.println("Finished!");
}```
How it works is that the Arduino waits until the Pi sends the string "A" or "B"
Then it sends confirmation and the Pi sends a number of steps
Then the Arduino moves the given motor that many steps before saying it's done and letting the Pi give it more instructions
I can't see how it favors motor A more than motor B though
is there a way for a led to turn on when a button is pressed and stay on until the button is pressed again without Arduino and just simply logic components
google up "flip flop circuit"
okay thank you very much!
You can build it out of logic gates, or just two transistors (or vacuum tubes) and a handful of passive components.
does the circuit change if i need like 50-60 buttons and leds?
That depends. Are they all independent (that is, each button has its own LED that it controls) or do they interact somehow?
yes they are all independent
i think it should be a simple circuit but i have no idea
Yes, it's a fairly simple circuit, but you'd need one for each switch/LED.
What syntax would I use to change " delay(750) ; " to a random value between 25-750 ? (or link to appropriate function?)
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Thanks. I couldn't find my bookmark to the reference pages.
Hey, quick question: rtc.adjust(DateTime(F(DATE), F(TIME))); just sets my system time as the rtc's time?
@atomic goblet It sets the time that you compiled the program as the RTC's time.
any idea why I might be getting these rythmic spikes in my temperature data
using the DS18B20 sensor until my thermistor arrives
going to plot it again in 7 hours or so to see if it continues
feels WAY too uniform to be real
better look
What is the horizontal axis? I mean, what unit of time? @mellow flax
So that peak happens every 20 minutes or so?
around 30
its within the documented error of +- 0.5
but the rhythmicity is rlly weird
Is there anything else that turns on/off every 30 minutes where you are?
not that I'm aware of
going to bed
I'll try powering it up with my UPS when I wake up
Looks like air conditioner/heater cycling to me.
hi i have problem with my esp8266 board im trying to do code with display and i define pins #define CLK D2 #define DIO D3 but every time it said D2 was not declared in the scope
hi i have problem with my esp8266 board im trying to do code with display and i define pins
#define CLK D2 #define DIO D3but every time it said D2 was not declared in the scope
@rugged smelt
https://github.com/ThingPulse/esp8266-oled-ssd1306/issues/156
this might help you
different 8266 boards have different gpio notation
thanks
Hello, I have been struggling to get my Adafruit Huzzah feather to connect to my laptop (OSX 10.15.6). Are these perhaps deprecated? I'm assuming my troubles are with the SILabs USB driver. The port does not appear in the arduino IDE and the extensions shows "No" under the Loaded column when I run a system report. There is nothing to enable/authorize in the security area and I found another post related to forcing it to be allowed in recovery mode. Currently out of ideas and thought I would reach out here.
Apparently Apple started shipping their own driver for the CP2102, but it binds to all devices in the CP21xx family but doesn't support any of the other ones.
Apparently Apple started shipping their own driver for the CP2102, but it binds to all devices in the CP21xx family but doesn't support any of the other ones.
@north stream Are there any work arounds? Maybe I'll use the PC in this case.
If that's the problem you're having, the workaround is to disable the Apple driver and install the Silicon Labs driver. https://www.decisivetactics.com/support/view?article=device-notes-silabs
Apple appears to have removed the problematic driver as of macOS 10.15.3.
Well it looks to be working now. Thanks for the information!
Thanks for the update!
Well, another issue while learning here, I've re-written it and I cant figure out why I get this on the serial monitor, I've only given the one input.
float radius;
float area;
float pi = 3.14;
String msg = "What is the radius of your circle?";
String msg2 = "Your circle has an area of ";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(msg);
while(Serial.available()==0){
}
radius = Serial.parseFloat();
area = piradiusradius;
Serial.println(area);
}
serial monitor:
What is the radius of your circle?
6358.50
What is the radius of your circle?
0.00
What is the radius of your circle?
I'm guessing here, but I think parseFloat() grabs characters as long as they're numeric, but when the loop comes around again, the carriage return is still there?
It also did it with parseInt()
It's throwing me off because I don't want it to mess up anything in the future. At first I thought it was the Raspberry Pi I'm using, but I get the same results on my Windows PC.
You can do parseFloat(SKIP_WHITESPACE) to have it skip over carriage returns, if that's the issue.
Unfortunately that didn't change it.
Is there about a 1-second delay before it continues? If so it's probably hitting a timeout, so you could increase that with Serial.setTimeout.
Where would that go then? I'm unfamiliar with that command.
And about 1-2 sec, yes.
setting the serial monitor to "No line ending" works, is it set to "Both NL & CR" now?
this is the output with inputs of 50 and 40:
7850.00
What is the radius of your circle?
5024.00
What is the radius of your circle?
Holy crap, that was it! Thank you! It was bothering me all day. And of course the tutorial was following never brought that up.
Would it be a good idea to keep that setting all the time?
it depends on the application, many things look for input to terminate with CR (0x0D), LF (0x0A) or both
in this case the (SKIP_WHITESPACE) caught the carriage return but not the new line
Seriously? Lame... Good debugging, though. ๐ฏ
now i just wonder why it's "NL & CR", nobody uses LF + CR, it's always CR + LF...
hey could anyone help me with some code im fairly new to arduino and im trying to get an oled working
any help much appreciated ๐
If you post your code to paste bin and share the link, it will help
so im just trying to find my oled's i2c address and i found some code that should do it. I installed all the libraries that needed to be used but i might have missed one because when i verify the code i get an error message
Add quotes around wire.h
Or no sorry
#include <Wire.h>
Try without the space and capital W
https://www.arduino.cc/en/Tutorial/DigitalPotentiometer see the example code on this page for using Wire
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
The overarching concept is the same
thanks! it seems to work but i might need more help in a couple minutes if you can
Sure!
@gilded swift never mind i got it working thanks for your help
Youโre welcome ๐ค
@obtuse spruce yes the stm32's have wire.h and spi.h
i got i2c working.. but absolutely no SPI what so ever besides the CS line
I didn't have time to figure out what it was doing/where it was actually going to..
but it wasn't going to any of the stm designated spi pins...
i finally broke down, and tried an UNO... (not enough memory again)
and then moved on to a 2560... which worked as expected first try...
too bad i deleted 90% of my code troubleshooting all of these other MCU's that didn't work..
oh... the ESP wasn't working either.. again.. SPI never worked on any of the designated pins... only CS was working...
(So glad I just stumbled into starting out with a Feather M0 and Feather M4... everything on them has "just worked" ... and plenty of everything to play with.)
I've had similar experience, the ESP and nRF chips seem to be a little rough around the edges, but the M0 and M4 (and Teensy) are solid.
My servos are jittering when I connect them to the arduino
Im also runnin 2 roboclaws and 2 distance sensors with the arduino
could it be because of not enough current
Does anyone know if arduino IoT cloud is compatible with wpa2 enterprise networks?
speaking of arduino IoT, I have one of these https://store.arduino.cc/usa/mkr-wifi-1010 from an iot convention and I'm wondering if I can use this with some neopixels to make some accent lighting at my desk, but the adafruit neopixel guide says the neopixel library is made for "most anything with an Atmel AVR 8-bit processor from 8 to 16 MHz", and the arduino mkr has a cortex m0, so I'm unsure if it's compatible?
The basic Arduino board to build secure WiFi and Bluetoothยฎ applications.
ok so I got the ide set up and when I try to use it I just keep getting this error every time I try to load code onto the board
I can't figure out what I'm doing wrong with this
(this happens regardless of what code I try to upload, btw)
this also happens when I use a different USB port on my computer.
ah, nvm, it just appears windows is being windows, I switched back over to mac and it's working fine now. hooray, rainbows are filling my room
@ivory gorge for m0 based boards, your best choice is using neopixel dma library: https://learn.adafruit.com/dma-driven-neopixels/overview
@atomic goblet It sets the time that you compiled the program as the RTC's time.
@lone ferry it doesn't work. I think I killed it while soldering it on :( it either shows the time i disconnected it before soldering or year 2165.. ๐ if I try to enter a specific time there's no change in the output
@vivid rock thanks for the tip! I modified one of the default (non-dma) samples to strip out all the things I didn't need and it worked perfectly, thank you for the help though!
@atomic goblet What if you remove the battery? That will reset the RTC.
hey, if I want to control the on off an dc motor (water pump) with a remote control what can I do? I have the code for the ir remote, but I don't know how to control the motor, that it has just 2 cables....
@atomic goblet What if you remove the battery? That will reset the RTC.
@lone ferry I don't think I can remove it. It is not soldered but glued I think. I'm kind of hesitant to just ripe it out
@atomic goblet What is your full Arduino code for changing the time?
@atomic goblet What is your full Arduino code for changing the time?
@lone ferry I used the sample included in the ds3231 library. Just picked the code from above out of the condition brackets and ran it
Could you copy-paste the entire program anyway? Sometimes what people describe isn't actually what the code does. ๐
@deep tapir While it could be a current problem, I'm guessing it's more likely a timing issue or electrical noise.
so i know that PyQt is just a python wrapper for Qt C++, is it better to port my PyQt Gui to Qt C++? and is it easier to create a .exe file for that?
How can i check if my Atmega 32A microcontroller is bootloaded or not? Also can i Bootload my microcontroller with FTDI ?
as for figuring out if it is bootloaded, try to upload a sketch to it
Using FTDI?
yeah
ft232r is a pretty common USB to serial IC for programming sketches
you would need to connect it to the tx/rx pins (crossed FT RX to 32A TX, FT TX to 32A RX)
hmm alright Thanks i'll try it.But im not sure if i can upload the code with atmel studio cause it's require it's own AVR programmer like atmel ice
you can download the adruino ide
i already have installed. ok i try uploading blink sketch to it using arduino ide