#help-with-arduino
1 messages ยท Page 10 of 1
thank you! ๐
Chips like these:
https://www.analog.com/en/parametricsearch/11390
Analog also has some high voltage digipots, but I don't think that's what you want here.
Small disclaimer: I work at Analog
(on automotive video chips, but there are some biomed guys in the same lab)
Very thankful for you saying that, do you think you could help me build what I want to build? ๐
Ive been working on this for 9 months ๐
Not officially, no. I am not an applications engineer, and the things I say here do not represent the company. Sorry.
I'm happy to answer electronics questions and try to point you in the right direction though.
I understand!
Analog does have a lot of biomed chips, including EEG and ECG. But those are for sensing, not neurostimulation.
okay and what kind of advise would you give me if I needed to finish my medical hardware
Probably something along the lines of "talk to an applications engineer". I can't guarantee a response, but all of the apps engineers I've met have been very competent in their respective fields.
okay, help me finish my board with potentiometer
MDAC instead of potentiometer, please! ๐
how would you wire this? ๐
MDACs are a bit weird, and usually need some external circuitry. They usually do best as current sinks. I would recommend taking a look at the end of some datasheets. They usually have some info about how they work.
but I can wire them as simply as potentiometer?
okay so I just leave 1 output open ๐
i cant get it done, I need your help, how can I connect this one and how can I even programm it? Isnt it completely unuseful? I can make a good enough POT in 20min
@random zealot You need to seek professional help, what you are attempting is dangerous (electrostimulation, but anything >=48volts is considered unsafe in the UK). As Herr Brain said, an application engineer can guide you through your design goals and component selection. Most components offer a reference design (working circuit schematic), which is the minimum required to operate, and can be copied reliably.
More than that, if you say you have built 60 of the hardware devices already, then you really need to get professional help before you go any further, both for safety reasons, and because component selection will probably change the hardware design. Software is a secondary concern.
and where do I seek help from ๐
are you doing this for yourself, or are you working at a research institution or university?
I am working with both and I have like 60 specialists behind me who told me nothing about "professional help"
are you being paid by an institution? what country is it in?
it would be very good to seek the help of one or more professional electronics engineers, who specialize in medical devices. There are a great many regulations surrounding medical devices which are concerned with safety in all the countries I know of, and I assume the same is true in Slovakia. Can you find such a resource?
Medical devices need to be tested and certified
I have talked to 500+ of them
every single one tells me a different answear on my baord
and my competition is literally rying to manipulate me and them into doing that
But you yourself do not have the expertise.
do you mean your message board, or your company board?
I do, I know how to build the device from anything
I literally can build it from a 9Volt
As Herr Brain mentioned, you can consult with applications engineeers at Analog and other places. But it sounds you like need to hire an EE experienced in this field who you can trust. We cannot give you advice in this server for potentially harmful applications.
Our Code of Conduct says this is not allowed:
- Discussion or promotion of activities or projects that intend or pose a risk of significant harm
neurostimulation without extremely careful consideration of the currents and voltages is such a project
that is what is worrying us
I am speaking as a moderator of the server
@random zealot The general advice to seek professional help seems unhelpful, but there are different pro's with different expertise. The component manufacturers have Application Engineers that will guide you for your application to choose good components.
Also a Medical Device engineer or similar is required for your needs, along with legal help probably. This info about slovakian stimulation devices and testing may offer you further guidance but is probably already known to you.
Before soldering wanted to test the pled feather. Jumped off the 3.3v from the rp2040 feather then connected i2c. Loaded sample code into arduino ide uploaded but not seeing any changes. Perhaps someone can point out how Iโm failing
This was the solution for a problem my friend recently had: solder those pin headers to the boards
He wanted to test something, had it set up like you, it didn't work. As soon as he soldered the pins, it worked
I managed to use a thin string woven in some of the header holes, it forced the pins against the header holes, alternatively anything non conductive
https://learn.adafruit.com/adafruit-oled-featherwing/python-circuitpython-wiring just looked and saw a demo of how it should be wired up
not enough jumpers plugged in!
100% right on soldering btw. Had to hold it down for a stable connection
Is there a proper way to test/connect boards before/without soldering in pins/wires?
Like some spring-loaded pins? Or banana plugs except smaller? Clips?
I mean, there has to be an "official" way, right?
The little mini-grabber hook clips may be helpful for that.
Professional setups often use jigs with pogo pins on them to connect to test pads on the board.
https://www.adafruit.com/product/1008 I guess these are too large, right?
Yeah, alligator clips aren't great.
are they small enough for those breadboard-friendly solder pads?
I can't really judge that from the pictures. But I guess I could just add them to my next order ๐
Professional setups also use the mini grabbers.
This breadboard uses miniature 2mm banana plugs
Thank you a lot! ๐
Hi everyone;
I've run into a problem with circutmaker (altium) and I'm looking for help, does anyone have time to help out?
You'll never know unless you ask the actual question.
Please don't double post. People come and go and there may be no one around at a particular moment. Personally, I've never used Altium as it doesn't run on any operating systems I use.
anyone know how i can make the file system visible in windows / linux / mac or whatever with the Pico W running C/C++
im looking through the docs but i cant see it in there
guys i need to reproduce this with 30 resistors and 1 digital switch
please, is there something like potentiometer? And i cant use MDAC ๐
Well, low on resistance analog switches/multiplexers exist.
I donโt think 30:1 muxes exist though
Thatโs 5 control signals too
You could use a smรถl fpga
It looks like you're trying to implement a switchable current regulator. There are easier ways to do that.
Programmable regulators exist for that reason
Note: as drawn, it won't do what you want anyway.
Thanky you guys! ๐
I recommend you use the earlephilhower arduino-pico core and not the "official" mbed one.
Then I think you can use the Adafruit-TinyUSB stack. It has some examples
https://arduino-pico.readthedocs.io/en/latest/usb.html
https://github.com/adafruit/Adafruit_TinyUSB_Arduino
thank you so much, i've been searching for something like this for hours 
i just looked through the Pico C SDK and i realised that there is already a TinyUSB library installed
yes. The Pico SDK has TinyUSB
i just need to figure out how to include it
is it just
#include <tinyusb>
or am i missing something
I think the Adafruit TinyUSB is just a more arduino-friendly version of TinyUSB
Honestly, not sure. I haven't used all that stuff yet :/
well its confusing because vs code is useless because valid libraries show up as red squiggly lines
they compile perfectly fine but vs code is a pile of doo doo
like this just breaks
in vs code but works normally when i compile
ughhhh yeah... I use vs code with platformio and the earlephilhower core. Most of the time it works. But sometimes it just randomly thinks some include path is wrong ๐
lmao i dont even know how i can like make it know that im using the pico sdk
lemme see if there is an extention
there isn't
so it shows up
bnut its red when i load it 
stupid vs code
when i remove the include it knows that the headers aren't there
so surely it should know that its a valid include
What does your cmakelist.txt look like?
it's the default one, one second
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
set(PICO_SDK_PATH "/mnt/d/Github Repos/PicoDuckyC/pico-sdk")
set(PICO_BOARD pico CACHE STRING "Board type")
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
project(ProjectName C CXX ASM)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# Add executable. Default name is the project name, version 0.1
add_executable(ProjectName ProjectName.c )
pico_set_program_name(ProjectName "ProjectName")
pico_set_program_version(ProjectName "0.1")
pico_enable_stdio_uart(ProjectName 1)
pico_enable_stdio_usb(ProjectName 1)
# Add the standard library to the build
target_link_libraries(ProjectName
pico_stdlib)
# Add the standard include files to the build
target_include_directories(ProjectName PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
)
# Add any user requested libraries
target_link_libraries(ProjectName
)
pico_add_extra_outputs(ProjectName)
i forgot to change the project name 
Yeah, make sure to update your file name in there too
yeah i will once i get used to it
this is just a test project im not gunna keep using it its just so i know how to use the SDK
then i'll build what im actually trying to build
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:251:2: warning: #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked [-Wcpp]
251 | #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked
| ^~~~~~~
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:252:1: error: unknown type name 'bool'
252 | bool stdio_usb_init(void) {
| ^~~~
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:1:1: note: 'bool' is defined in header '<stdbool.h>'; did you forget to '#include <stdbool.h>'?
+++ |+#include <stdbool.h>
1 | /**
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c: In function 'stdio_usb_init':
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:253:12: error: 'false' undeclared (first use in this function)
253 | return false;
| ^~~~~
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:253:12: note: 'false' is defined in header '<stdbool.h>'; did you forget to '#include <stdbool.h>'?
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:253:12: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/PicoWDuckyC++.dir/build.make:605: CMakeFiles/PicoWDuckyC++.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1789: CMakeFiles/PicoWDuckyC++.dir/all] Error 2
make: *** [Makefile:103: all] Error 2```
apparently it doesn't know what a boolean is
im so confused
I think thereโs something else going on here..
Probably something not getting linked properly
maybe but its confusing
It does suggest including the stdbool.h header, maybe do that?
Weird thing is stdio_usb.c is part of the Pico sdk
It should have it automatically
Which makes me think a breaking change happened at some point in the sdk
Or perhaps they need to reclone the pico sdk
Or the toolchain
That too
can you tell me how to change plus to minus voltage and vice versa? ๐
H bridge๐ค
I need help with coding ๐
with what?
its very complicated but arduino circuit ๐
then you should imho describe the circuit, describe what you want to do and where exactly you need help
Just swap the red and black wires. ๐
in other words, I want to make alternating current
I have 30V output that goes from 0,1-10mA but it doesnt describe whether it is positive or negative
so how to make this current output alternating? ๐
dc to ac converter?
it already is DAC and it goes to current regulator
so the current can sty and it is just the voltage that has to go from neg to positive and back?
You can't regulate both. You have to be actively controlling either the voltage or current. The other will track depending on your load. Also not to soft mod but remember the code of conduct.
Yeah, I really tend to think if you are making a device intended to be used medically that you should hire a professional engineer with the skills do make what you are describing. Note that it absolutely has to be reviewed by a board of professionals anyway in most EU countries and for approval in the US. Even just to sell in the EU/UK you need very specific testing which will require you have a professional engineer anyway. This discord really isnโt the appropriate place to get advice for medical devices, and honestly opens up a bit of liability that I doubt many would want to deal with.
At least in the U.S. you can't even build a medical device and then get it certified later. The certification process wants to look at the whole development along the way too, making sure that way done properly.
i dont think im googling the right thing can someone help, with the Pico SDK how can i make the on board flash memory show up on a computer when it's plugged in
as a mass storage device*
You can make the RPI-RP2 drive show up by unplugging the Pico, and plugging it in while holding the โbootโ button
i dont mean like that
i mean like
idk
yk when you install circuit python
the uf2
once that's installed
you can still write to the flash
i dont think im making sense
Oh, you want a file system on your not Python environment
yes filesystem
im using C++
but i cant find it in the SDK documentation anywhere
it thinks im adding an SD Card reader
every time
I donโt know if it shows up as a mountable drive, but you can create a file system with I think it was LittleFS?
You can use TinyUSB I believe
i've read through the library for tiny USB but from what i can gather it only allows external media
idk
is little FS directly readable on windows or do i need a tool to allow me to read the file system
typically i like my projects to require zero setup for the end user
they just drag and drop and or just open the executable or whatever
i think i can use Fat
iirc
but like, obviously before i can start coding the actual program i need to be able to let the user add files to the flash after the uf2 is loaded
in the adafruit tinyusb repo, there is an example to use it with littlefs (file system on the flash chip). Both adafruit tinyusb and littlefs are arduino libraries but maybe it can give you an idea how to do it without arduino and just the sdk
i tried that
i have that currenlty compiled
and running on my pico but it doesn't load
so do i like need some external software to be able to view the file system or something
Should just be file explorer or finder on Mac
then no, it doesn't work for whatever reason
i haven't even modified it at all
i tried it both on a pico and a pico W
and neither work
Does it show up under device manager? Or under /dev/ as a usb device?
ooooo boss thinking
i haven't checked
nope, doesn't show up on COM either
i have zero communication but i know its running the binary because the led is blinking
okay i added cmake pico_enable_stdio_usb(project 1)
to the cmake file
now i have a compile error
unrelated
[ 69%] Building C object CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c.obj
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:252:2: error: #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked [-Werror=cpp]
252 | #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked
| ^~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors
[ 70%] Building C object CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_unique_id/unique_id.c.obj
make[2]: *** [CMakeFiles/msc_file_explorer.dir/build.make:657: CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 71%] Building C object CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/hardware_flash/flash.c.obj
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/hardware_flash/flash.c: In function 'flash_range_erase':
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/hardware_flash/flash.c:71:30: error: declaration of 'flash_range_erase' shadows a global declaration [-Werror=shadow]
71 | rom_flash_range_erase_fn flash_range_erase = (rom_flash_range_erase_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_RANGE_ERASE);
| ^~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/msc_file_explorer.dir/build.make:696: CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/hardware_flash/flash.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1761: CMakeFiles/msc_file_explorer.dir/all] Error 2
make: *** [Makefile:103: all] Error 2```
i removed the cmake line and the compile error has gone
i ran make clean
then compiled again
io_usb/stdio_usb.c.obj
/mnt/d/Github Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c:252:2: error: #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked [-Werror=cpp]
252 | #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked
| ^~~~~~~
compilation terminated due to -Wfatal-errors.
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/msc_file_explorer.dir/build.make:657: CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb.c.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 69%] Building C object CMakeFiles/msc_file_explorer.dir/mnt/d/Github_Repos/PicoDuckyC/pico-sdk/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c.obj
make[1]: *** [CMakeFiles/Makefile2:1761: CMakeFiles/msc_file_explorer.dir/all] Error 2
make: *** [Makefile:103: all] Error 2```
that's with the cmake line
Hmm interesting
i need that cmake line because i dont have headers on my pico w so i cant use uart
with the pico probe thing
IT SHOWS UP
BUT NOT AS A MASS STORAGE DEVICE
i've managed to get it to show up in device manager
Driver Name: null
Class Guid: {00000000-0000-0000-0000-000000000000}
Driver Date:
Driver Version:
Driver Provider:
Driver Section:
Driver Rank: 0x0
Matching Device Id:
Outranked Drivers:
Device Updated: false
Parent Device: USB\VID_2E8A&PID_000A\E66118604B5D2627```
ayyyyyyyyyyyyyyyyyyy
Question: i have an Arduino mega and want to use 18 arcade buttons. The buttons have 12v leds and i want to use 12v for them from a power supply so they are bright enough t use during daylight. I'm thinking about using two ls2 level shifters so my signal from 5v Arduino will light the leds of 12v on the arcade buttons. https://www.ezsbc.com/product/ls2/ is this a safe construction? 5v to V-in, ground to in I-ground, 12v to V-out ground to O-ground and then then 5v signals to i-1 to I-8 and 12v to 0-1 to O-8
I am not familiar with that shifter, but I suspect it's a logic level shifter, and may or may not have sufficient current capability to drive LEDs. I might use something like a TPIC6B595 high power shift register, connecting each of the 12V LED anodes to 12V, and the cathodes to the shift register outputs. You'd need two of the 8-output chips to control 12 LEDs.
I want to make a controller using joysticks and a arduino micro
I want to add two analog triggers though and I dont know how
I don't know the pinout neither the code has to be
Can someone help please ?
Can you share what youโve tried so far?
Yeah nothing I just imagine
My suggestion, start with the basic examples Arduino provides, get a feeling for how analog inputs work on Arduino, then try what you want to do.
K
The best way to learn in many cases is to work through and try to understand the minimal examples. Theyโll give you the foundations for more complex solutions.
For two analog joysticks you'll need four ADC channels (x and y for each).
Most joysticks are basically just potentiometers. All you have to do is connect power and ground, then measure the voltages at the wiper pins.
I know
But I don't want joysticks
I want the analog triggers like a ps5
The complexity is in the firmware: do you need to filter the samples? How do you account for dead zones?
Same principle.
Yeah but how will a pc game recognize the potentiometers as buttons
Or is it not how it works ?
You still need to have a threshold value to know when to trigger. Reading the voltage and sending a USB/Bluetooth HID command
Most game controllers now use USB HID, so essentially what you'd have to do is emulate an existing controller.
If you want an analog trigger, it will show up as an axis.
Yeah but wait
I thought that it works like
If it's at 512 it's medium
If it's at 700 it's semi high
Some like that
Or is it like a button?
So there is no reason to add an analog trigger?
Yes, but what if it's at 511, or 515? Do those still count as medium?
That depends on what you are wanting to control.
Let's say
I have a game
In which game
If you press the trigger ligthly
A water pistol shoots slow
Then when pressing it medium
It shoots faster
And etc etc
How would that work
?
But also
I want it to work like buttons to a game that does not recognize such mechanisms
If you have a microcontroller, that can do HID, you can do whatever you want. But the game of course needs to support it in some way
For example if the game doesn't support analog triggers, but it does support 3 buttons for "shoot slow", "shoot medium" and "shoot high". Then you could read the analog value of the trigger and depending on that send a button press for slow, medium, or fast.
Technically HID isnโt built in, it just has library support
Yeah but how to achieve that
Ok, I think I see where you're going with this:
- There's a game you play that lets you shoot something as fast as you can push a button.
- You have a squirtgun and want to change how fast the game gun fires based on how hard you pull the trigger.
Essentially youโll translate analog voltage ranges to values sent over HID that correspond to expected values for trigger pressure
If the game is expecting a button input, you will need to produce what the game recognizes as "button presses" at a rate proportional to how hard you are pulling the trigger.
๐
They even have the ones for golf lol
Idk if map is the command because I forgor
But can I map the potentiometer
Potentiometer input?
How is it called ?
I think input
To 10?
Like 1023 will be 10
And 0 0
So
There will be modes ?
So 0 will be low
10 high
And the rest
Idk
Ok but
Problem is will that work ?
Like if I play a car game
And I press the trigger fully
It goes maximum horsepower
Slightly = less horsepower
None = 0 km
Can I?
Yeah, itโs all based on the max value that the HID can send
The HID document specifies what is standard and they donโt list a value that has to be max, only that it has a specified range. Those ranges and available controls are communicated when the device sets up with the computer
I think what you want to do is set up a counter with the maximum value controlled by your trigger. Each time the count reaches the maximum, it will reset. You can then use a software interrupt to toggle the "button" state.
Look at automobile control as a starting point since thatโs a pretty common example of ranged HID inputs
I want to drive a car at a game and depending at how hard I press the trigger it's speed increase or decrease
But
At another game
Which such mechanism does not exist
I don't want to change the whole code
I want the code to support both modes
It will just take the min and max value in those cases
Idk if that's possible
This is a good example, but in that case the game is expecting an analog input. In this case it sounds like the game can only map a button press.
That assumes they have some degree of control over the game.
For ones where there is no variable acceleration, it would simply catch the โnot pressedโ and โfully pressedโ inputs
I would add a switch to your device to select the mode you want
Oh okay cool
If I were to guess, this sounds like a first person shooter that they want to build a custom controller for. I've never seen an FPS game that allows you to control rate of fire with an analog axis.
hopefully not offtopic: If that game is a multiplayer game or features leaderboards, scores, etc, make sure that what you're doing isn't cheating.
Imho building a device that can fire faster than me clicking the mouse, could be considered cheating
But that analog trigger also allows you to have variable acceleration in racing games too
Thatโs why Iโm saying that you donโt need to try and support both in code because itโs already supported in the host
Meh. As long as it's nothing superhuman or game-breaking I'm willing to consider this type of thing to be an accessibility tool.
No no
That was an example
Why cant we say he ll no
I wanted to say bruh he ll no to your message penpengu
Swears are blocked by the bot in this server
The word is considered vulgar to some people
So while it might not be bad to a subset of people, it can be to others
Well done
First server that supports crrhistianity
Religions in general
๐
We support all people as long as they are not rude or hateful towards others
See #code-of-conduct for a more detailed explanation
So, what are you trying to do? Are you using this for a game you are writing?
If so that could significantly simplify things.
No I want to make a controller
Like a ps4 or ps5
With analog triggers
... so basically you want to plug an xbox controller into your playstation?
I donโt think PlayStation 4/5 games support analog triggers?
I thought the controllers used push button triggers
Oh the new ones have adaptive triggers which are basically motors with worm gears which then provides a voltage input to the controllers MCU
yeah, they're really cool tech ๐
But also used to change the feel of the trigger too. Neat
I think the triggers on the PS4 are normal analog
fun fact: the triggers on the XBox one controller use hall sensors (or something like that. It's definitely contactless)
But most third party Xbox one controllers use potentiometers
I bought one with the clear case because why not
Interesting how long it's taking them to switch the thumb sticks to hall ๐
I love clear electronics! Sadly there are way too few ๐ญ. I wanted to make my Xbox one controller clear but the clear replacement case was just absolute garbage quality
Is there a way to get the file system to show up on windows when using an Arduino program?
The SPI flash example can write a file to the circuit python's filesystem
And if circuit python is installed you can read the file on the computer
Ok wait I forgot the details
I'm using a CPX and writing to the onboard flash
So my question is
Can I somehow mount the drive with the circuit python files from an Arduino program?
yes, there's a recent library, let me find it
Update: read the TinyUSB description and looks like what I need, but... can't get the option under tools to get it to compile
are you looking at this library? https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/examples/MassStorage/msc_external_flash/msc_external_flash.ino
Yea id that the right one?
Tried installing the Adafruit SAMD boarda instead of the Arduino ones
And after adding the custom board url it showed up to install
yes, was just verifying there wasn't some thing more specific or newer
you need to install first the Arduino and then also the Adafruit SAMD boards
yes, I think I have a pointer to describe that ... hold on
Huh
Uninstalling and reinstalling made the boats show up
the CPX board def is actually part of the Arduino SAMD, unlike other Adafruit SAMD boards
But is it also part of the Adafruit SAMD boards?
For instance, this is for Feather M4 https://learn.adafruit.com/adafruit-circuit-playground-express/set-up-arduino-ide
Since I read somewhere you gotta use that to use TinyUSB
anyway, install both
Ok
swing back if you get stuck -- this is ongoing ๐
Yay it worked! Thank you so much!
Quick question about EEPROM availability. Under normal circumstances (that is, not using any libraries that explicitly need EEPROM storage) I should have free reign over the entire EEPROM region of a chip, right? It's not like I run the risk of stomping on a piece of data that the Arduino IDE is going to expect to be available for some low level function?
I know that the EEPROM and program storage are different regions, so this isn't about stomping on the actual code.
In general, the EEPROM is yours to do with as you please.
Awesome. I only need one byte, but just wanted to make sure that going with the obvious choice of byte 0 wasn't going to be a problem.
I saw one project that needed to store a single byte that hid it in one of a few bytes of battery backed RAM in a real time clock chip.
I saw one project where the guy needed a few extra bytes of RAM, and took over a number of registers for functions that weren't actually needed.
The crazy things that can be done
Oh, that works. I saw another one that used the custom character storage in an LCD display to cache some data.
Oh, the fun thing with that is you can include a function to let you directly view the memory in question.
That's handy!
For my purposes, I want to allow the option of attaching a button, and swapping between two sets of switch settings, and have them persist after poweroff to avoid reconfiguring every time since the controller may not always be easily accessible, nor is reconfiguring quick.
Set the switches to one mode, hold the button to save. Then change the switches to a second mode, and tap the button to toggle them.
Also useful if you only want one mode, but the ability to turn the lights off. If the saved and physical settings are the same, toggling will turn the lights on or off.
The main rule with EEPROM is that you want to try to limit how much you write to it. Like flash (actually the reverse since flash was derived from EEPROM), it has a finite lifecycle. A discrete EEPROM can usually handle 1-2 million writes, but for microcontrollers this will typically be an order of magnitude lower.
Oh I should be getting nowhere near any wear limits. This will get written like, a few hundred times over the life of the unit.
Yeah it's fine then.
I'm not even going to do a sanity check on the value on bootup because ultimately any 8 bit value will be valid for something.
The only other (potential) issue I can think of is some library wanting to store its state, but this is rare
Yeah, that's what I was mostly worried about. The only library I'm importing is the NeoPixel one, which is unlikely to need it.
Yeah should be fine then.
I figure though, any libraries that would want to use EEPROM would be fairly explicit about it, and in a sane world would have to configure where in EEPROM their data will live specifically to avoid conflicts.
Yeah
can anyone recommend a microcontroller with support for around 15 - 20 digital pins and space still for 6 analogs?
also data which can be sent over usb. for a gamepad
i was looking at esp32 but dont need wifi or bluetooth
The SAMD21 (AKA "M0") comes close: https://www.adafruit.com/product/2772
thanks @north stream what's the black housing for next to the usb?
That's for a lithium polymer cell, the board includes a charger so it can charge the cell when it's connected to USB, and run from the cell if it's not connected to USB. If you don't need battery functionality, you can ignore it, the board runs fine without one.
you can use a matrix to use fewer digital pins for the buttons
dont know what a matrix is sorry
google "keyboard matrix" and I bet you find an explanation that's better than what I could write ๐
this principle is used in PC keyboards as well
๐ค i don't think so
https://pcbheaven.com/wikipages/How_Key_Matrices_Works/ (Just skimmed it, looks like it could be a thorough explanation about keyboard matrix
I'm partial to the HT16K33 for driving keypads (it's technically an LED driver, which is useful, but includes keypad functionality). But you can use a few GPIOs in rows and columns to read an array of switches.
i mean the esp32 or the adafruit feather has pins for all my needs
and maybe if im smart i can send data via esp32
๐
I don't think all ESP32 have native usb, just pay attention to that when choosing it
still, just because you can upload your program using the USB port on a dev kit, doesn't mean that the microcontroller can also act as a HID device (game controller, Keyboard, Mouse, etc)
yeh wise words i'm probably going to copy a tutorial exactly
๐ sounds like a safe plan
The 32U4 is a nice one, with native USB/HID support, 5V logic, and several existing projects using it as a keypad. The RP2040 is another possibility.
RP2040 only 4 analog inputs :/
but Raspberry Pico only costs like 4โฌ so maybe you could just use 2 ๐
the problem im facing is the software ecosystem around rk3588 chips from rockchip. there's lots of deadends so i feel offloading to a dedicated feather board will allow more flexibility
also adafruit-mcp3xxx hasn't yielded results for me yet with it only returning a max / min value.... however i'm still figuring out if i'm using the right pins
i can't seem to build retroarch in armbian atm altho i'm told there's an aur source that might build, yeh definitely ideally armbian but still not making the big break throughs
batocera is using build root so limited library support unless they are bundled
it's just a mess in my head atm
yeh 2040 just falls a bit short, thanks for helping
esp32 seems to be the way over bluetooth
thanks @north stream i think 32u4 is going to be the one here. it's got the analog chanels and enough io
a bit more pricy than i hoped but it's a one time thing so why not
you do know it has extremely little space for programs right ?
like 1KB/3.5KB 16kb firmware
must be enough to receive and store the values then broadcast as keypress
im dealing with a 9kb file in python
basicaly a port of that
Note that the 32U4 cannot run Python, so you'd have to port the code to Wiring
I cant figure out how to talk to my pico W in the arduino IDE
I installed the board manager URL and everything it propose to download, I see the UF2 files on my G: drive but cant get board info no matter what port I choose and adafruit learn doesnt seem to say much except to use the board managers URL and everything should happens by magic or something then it just talks about circuitpython. Also on Im the more recent arduino IDE and I cant find tools->board manager
I installed the board manager URL and everything it propose to download, I see the UF2 files on my G: drive but cant get board info no matter what port I choose and adafruit learn doesnt seem to say much except to use the board managers URL and everything should happens by magic or something then it just talks about circuitpython. Also on Im the more recent arduino IDE and I cant find tools->board manager
and Im checking that doc: https://arduino-pico.readthedocs.io/en/latest/install.html#installing-via-arduino-boards-manager
Arduino support for the Pico is known to be iffy. Some people apparently opt for the earlephilhower core instead.
yeah that is what I seem to have installed
their docs from the link above offer several install options one of which is a board manager URL
Does it show up in the ports list?
I went to https://github.com/earlephilhower/arduino-pico then I clicked documentation for the above docs link
Arduino MBED core doesn't even support the pico w at all. Not even the "blink onboard LED" example works with MBED core and Pico w ๐
(With earlephilhower/arduino-pico it should work)
yeah the board is installed and I selected the uf2 port but it keep showing a communication error with it
but the upload seem to have worked
something seems off here, why flashing just to upload a less than 1kb sketch...
The RP2040 has no internal flash. All firmware is on the external flash chip
why it's 600k, not sure, but may drag in a lot of libraries
The memory usage is so gigantic because it needs to pull in a giant firmware blob for the Wifi module and I think even an entire IPV4 stack because the LED_BUILTIN is connected to the wifi module and not the RP2040
did not see it was the W
ok so it seems everything seems normal to you so I will just get used to the pico W way of behaviours in the arduino IDE
the led blinks etc and if I disconnect it the program is gone if I hold bootsel and still there if I dont hold bootsel so it seems everything is fine and I can still recover
If there is a working program running, bootsel is not necessary, but if it's hard-crashing, you need to get it into boot mode manually (PenPengu can confirm).
exactly
so bootsel is hooked to tp6 right ? So I could mount another safer button externally instead of touching the tiny bootsel button and risking esd damage/pins damage right ?
like say a physical on off switch
Honestly, I'm not really worried about ESD damage with those boards.
When we worked with expensive FPGA boards, the prof told us to first touch the PC case or the USB on the board but idk
you could, but I've never heard of anyone zapping their board that way. If it's really low humidity, a wrist ground strap or just discharging yourself in advance is a good idea for anything.
Touching a radiator supposedly also discharges you
yeah i touch my pc case first. but even then in the final mounting the bootsel button will be facing down and not able to be used
then for convenience, sure
thanks for your help ! ๐ now I need to ask somewhere else so it can speaks with uart with a 5V 32u4
or replace the 32u4 with some arduino-shaped board that is 3.3V native
assuming it is a Leonardo or simialr
yeah those are the shifters I have and I cant replace the board it's a custom one for a robot kit(zumo 32u4) based on 32u4 atmel but it's not actually a due/leonardo
My old code uses a serial.println but that doesnt seem to go throught on UF2 port ??
I believe if the microcontroller features native USB support, that is what will be used if you initialize and try to use the "default" serial port. To use the physical pins you have to initialize a different serial port.
Try initializing and using serial1 instead of just serial.
I think you're confusing something.
You can use the USB-Port on the Pico (W) for anything you want. Standard is, that Serial.println() gets sent to the serial monitor through that USB.
Only if you hold the bootloader button while plugging in usb, then it's in the UF2 bootloader. While it's in the UF2 bootloader, your code doesn't run
nope not getting anything either with serial or serial1 also when I turn on serial monitor the uf2 port disappears and I have to upload with com3
UF2 is only the bootloader
but it does run on uf2 bootloader... that's what confuse me. The led turn on like I code it
and the led on the ir receiver is off when pin is initialised. And yes Im very confused this is my first time with an rp2040
I think maybe the UF2 port stays there in the IDE ๐ค
However, if you want to communicate with your code COM[SomeNumber] is correct
You can't communicate with your code using UF2
so Im supposed to reboot everything I compile a sketch and to put a sketch on it I have to hold bootself ?!
after flashing using the UF2 bootloader, the RP2040 automatically reboots and starts your program
no
2 ways to upload sketches:
- Hold Bootloader button while plugging it in. Then select the UF2 port thing in the IDE.
- Just plug in the Pico normally. Your code runs. In the IDE, select the correct COM[Number] port. Just click upload.
Still not getting anything and screenshot show Im trying to use both serial1 and serial COM3 shows the thing to the right
After uploading it should automatically start your program
But on the "hardware" level it seems to work. IR receiver light up when I use my remote and the led keep blinking so the program "works" just not getting any serial.println or serial1.printlin with the name of the button pressed
Serial = USB
Serial1 = UART0 (Pins on the side of the board)
Serial2 = UART1 (Pins on the side of the board)
thanks for your help it works now ๐
๐ฅณ
A random issue I just noticed:
while(!Serial) get's stuck. It only continues after I send one enter from the PC to the Pico ๐ค
yeah the while thing is what I needed for it to work
where as that is not necessary on the mega 2560
ah interesting
Protocol=UNKNOWN Hash=0x 13 bits (incl. gap and start) received OK ๐ฆ ๐ข Just like I thought my sony remote doesnt use a sony protocol supported by an arduino library ๐ฆ
to give some context: Ive been mapping manually between buttons and hex values but Id rather find a library that already has it. But only libc for linux has it (ie: a C++ RPI program. Since the ir receiver works now I want to all support for all buttons
13:54:43.775 -> P=SIRCS | 0x1 A=0xB C=0x9 13:54:43.900 -> P=SIRCS | 0x1 A=0xB C=0x9 R (VCR target version)
13:54:45.378 -> P=SIRCS | 0x1 A=0x1 C=0x9 13:54:45.517 -> P=SIRCS | 0x1 A=0x1 C=0x9 R (TV target version)
Hi, I have a project using an itsybitsy m0 that seems to be having some conflict involving the servo library and interrupts. I have a servo connected on D5 and an interrupt set up on A5. In my code, if I enable the interrupt and have the servo connected, the servo will twitch about twice per second. If I comment out the attachInterrupt in the code and upload, the servo does not twitch. I only see this behaviour when running off my ESC's built in BEC and not when the itsybitsy is connected my computer through USB
I'm getting the error
Compilation error: Adafruit_BLE.h: No such file or directory
which is odd because
a. I did install Adafruit BLE firmata library
b. I had a BLE example working yesterday...
oh wait wrong module thingy
Hi all! I have an esp32-s2 feather board (with the built in i2c lipo info chip) but I'd like to try detect if it's powered by usb or the lipo. Is this possible (without additional components)
if it is powered by USB, it is always connected to a computer? That is easy to detect: supervisor.usb_connected
that is in CircuitPython:
import supervisor
... supervisor.usb_connected...
on the board, in your circuitpython program: https://docs.circuitpython.org/en/latest/shared-bindings/supervisor/index.html#supervisor.Runtime.usb_connected
or you can connect a 2/3 voltage divider to the USB pin and check the level of that with another pin
Ah, so usb_connected would return true if it had a computer connected, but false if it was powered by a "dumb" usb supply?
right. usb_connected sees whether it's enumerated its USB devices to the host
that's really cool, but in my case this is for a iot'ish device that would most likely be powered by a dumb usb power supply.
then the voltage divider check is the thing
I really need to give circuitpython a go. I'm an actual python engineer but I got stuck in arduino land many years ago when circuitpython was still very new and never tried it out again.
yeah, I figured that might be the case.
oh, sorry, this is #help-with-arduino . I am jumping around in discord ๐
anyway, the voltage divider will work in for either
hey, it's all good ๐
Since you're. a core contrib, is vscode the best way to get going with circuitpython?
is there something like that on arduino? I don't think so ๐ค. I only know of if(Serial) and that only returns true if the serial monitor was actually opened on the PC.
(for someone who is already using vscode for work / python)
there is circuitpython plugin, I haven't tried it. Other good choices are Mu and pycharm.
thanks @stable forge
There are folks in #help-with-circuitpython who would be able to give a first hand review
not that I know of
It must be possible, but it might take some research to figure out how. I'd probably start by looking at the CircuitPython source code and seeing what it does.
Definitely. At least if you're using tinyusb. I don't actually need it, it just seems kinda weird to me that it's not there. Though I guess most of the time if(Serial) is all you need
It would have saved some effort on a previous project of mine where the touch sensitivity varied depending on whether it was grounded (via USB) or not.
I do agree it's a little weird, but I guess the original Arduinos had a separate serial chip, so didn't have a way to check for USB enumeration. The USB native chips (32U4, M0, etc.) came later.
sounds like an extremely fun thing to troubleshoot ๐ญ
looks like it might be USBDevice.configured(), if you are not using TinyUSB.
I didn't even know there was a USBDevice object ๐ ๐ Thanks
not sure how visible it is -- I cannot find real documentaiont about it. First saw it here while searching: https://github.com/pololu/a-star-32u4-arduino-library/blob/250648f9088c74704655e1cce22857d14f0c3c5c/examples/USBDetect/USBDetect.ino#L41C24-L41C44
doesn't seem like there is (on RP2040 arduino-pico) according to the IDE2s auto-complete :/
rp2040 is a different story -- it uses TinyUSB
oh right ๐
The USBDevice thing is for 32u4, etc.
I did ultimately get it working
Basically a Circuit Playground on a stick with copper tape touch rings to control it, for drawing in the air with LEDs
๐ฅณ
I see! that's why touch is more finicky. I assumed you meant a touch screen and thought that would be a design oversight that USB would affect the sensitivity
#include <tusb.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(LED_BUILTIN,HIGH);
}
void loop() {
if(tud_ready()){
digitalWrite(LED_BUILTIN, LOW);
delay(50);
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
} else {
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
}
}
Hardware: Pico-W with earlephilhower/arduino-pico
USB-Stack-> Pico-SDK (default)
I'm not sure how safe it is to just call tinyusb functions in your sketch. Didn't test if this interferes with USB-HID or USB-Serial. Because (I assume) it's only a check and doesn't do anything, I assume it should be fine.
However this seems to work. Connected to PC: it blinks fast. Connected to Phone charger: blinks slowly
When using TinyUSB, is there a way to detect when the file system is mounting?
Hi, im just switching from circuitpython too arduino and having some problems...
How do I define the pinouts for a feather v2?
I want to use SCK and A5
About to loose my mind on this. I am trying to use the NRF24L01 modules for a SIMPLE turn thing on and off. However I am having no luck in getting them to connect. I have tried about 10 different tutorials and guides, multiple arduinos, changed the wires, changed teh NRF module, NOTHING IS WORKING. I have used these in the past with ease in about 3 other projects but cannot get this to work. Can someone help me go through and try to fix this with me.
Really anyone with any experience with a NRF24L01 would be amazing. I am just wondering if I am just missing something simple.
I have also used an arduino nano
You mean in software?
not sure if i should ask here or somewhere else but when using ESP.Restart() to restart an esp32 board, does it do like a proper full restart or does stuff like the networking hardware retain their old state? im trying to figure out what i could do to make a full proper clean restart of the board from time to time
https://esp32.com/viewtopic.php?t=29658 It appears from other websearching that "ESP.Restart()" does try to start from scratch. The issue in the link is about finishing an EEPROM write.
someone seemed to mention also abort() there too
welp i hope that ESP.Restart() will be fine enough
i haven't heard about that. I'm not that familiar with the Arduino API
i see
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html?highlight=esp_restart#_CPPv411esp_restartv This function is exactly what is called when you do ESP.restart(). See https://github.com/espressif/arduino-esp32/blob/855f5261913c74e9f4f99fc0de184c847cc4db59/cores/esp32/Esp.cpp#L127
It says it does reset the WiFI and Bluetooth peripherals: Peripherals (except for Wi-Fi, BT, UART0, SPI1, and legacy timers) are not reset. I.e. Wi-Fi and BT are reset.
double negative that 's a bit confusing
I have both Arduino SAMD boards and Adafruit SAMD boards installed and when I plug in the CPX it auto selects it through Arduino boards. Is there any way to have it auto select the Adafruit SAMD version so uploading a new TinyUSB sketch is less annoying?
you could try removing the "Circuit Playground Express" lines from .arduino15/packages/arduino/hardware/samd/1.8.13/boards.txt. Save a copy of the file in case it does not work. Edit the file when the Arduino IDE is not running.
on Windows, the top-level directory will be Arduino15. I'm not sure where it is, but a websearch would tell you
I'm working with a Adafruit M0 Adaloggrer, right now trying to detect the SD card connected to the board
Thought this snippet should work to turn on/off the led depending on the card status
int button = 7;
int led = 13;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
digitalWrite(led, digitalRead(button) == HIGH ? HIGH : LOW);
}
The card is connected to pin#13 according to adafruit document Adafruit Feather M0 Adalogger Created by lady ada
The LED is pin 7
LED is working
But it does not change state depending on card insertion status!!
Any tips?
Looks right to me. I suppose you could view the pin state via the serial monitor, or attempt to measure it, if there's a way to probe that signal on the board.
You mentioned the LED being pin 7 but in the above you have it as pin 13.
And the button with a pullup on 7.
ahh... need do check... think pin nunbers in code is right though
yeah... i think the pins are under the sd card socket on the board.. need to verify that too. though
https://learn.adafruit.com/adafruit-feather-m0-adalogger/pinouts
#7 - used as the MicroSD card CD (card detect) pin. If you want to detect when a card is inserted/removed, configure this pin as an input with a pullup. When the pin reads low (0V) then there is no card inserted. When the pin reads high, then a card is in place. It will not tell you if the card is valid, its just a mechanical switch
Yeah 7 looks right for the CD so code numbers are correct as you mentioned.
.restart() does a full restart of the ESP32 board, including WiFi.
You can also use the WDT (watchdog timer peripheral) in ESP32 instead. I prefer this method for resetting WiFi state on ESP32 arduino boards as I can set a timeout period (in case something hangs/stalls internally like I2C). We use this in production in the Adafruit WipperSnapper firmware. The Adafruit_SleepyDog Arduino library provides a very simple wrapper around the ESP32's function calls.
@leaden walrus Ugh, ok, I'm confused here. This says that there are "two" I2C ports on the Feather RP2040, but schematic and so on says it's not a thing. https://github.com/earlephilhower/arduino-pico/blob/4c90b295b2a4aa2f2705469ade2fa987fd6b24f6/variants/adafruit_feather/pins_arduino.h#L33
Guide feedback says the I2C scan demo doesn't show the second one.
Both are showing up on WIRE.
I've found a few of those to be odd too. In theory, you could use D24/D25 as a secondary I2C on port0 (the primary / Stemma QT is on port1), so I think it's just making that a bit easier. But there are other pin combos you could use for a second I2c too.,
Running the demo and trying both options.
Uff.
That's a bit beyond this guide page.
@pallid grail try with latest BSP release. there have been some changes to the i2c pin setup stuff. those __WIRE0__DEVICE defines are new-ish
i'lll test real quick also
This machine is brand new as of less than a month ago, I think. I didn't transfer anything, so Arduino was installed fresh in that timeframe.
I can see if there are updates, but I think I have the latest.
No updates.
I think I have the info I need for this guide page.
I also updated the serial screenshot because it was before the two WIREs were swapped.
@pallid grail both work per those pins defines. need more info on what the confusion is.
using testbed scanner
https://learn.adafruit.com/scanning-i2c-addresses/arduino-using-testbed
This page is the "I2C Scan Test" template that goes into board guides. @leaden walrus It's not meant to handle other pin combinations. It uses the STEMMA QT port. I don't think there's any issue at this point. My confusion was stemming from the guide feedback. But I'm clear on it now.
can you link to that template page
fyi - there's this entire guide for i2c scanning:
https://learn.adafruit.com/scanning-i2c-addresses/overview
oh. think i found it. this page:
https://learn.adafruit.com/adafruit-feather-rp2040-pico/i2c-scan-test
uses testbed
@pallid grail the philhower core behavior has changed w.r.t. i2c pins and resulting Wire. older original behavior was using any pins that were RP2040's I2C0 peripheral became Wire and pins using I2C1 peripheral became Wire1. so STEMMA QT on Feather RP2040 ended up being Wire1. but now the core allows mapping to either - that's what these lines are doing in that BSP pins files:
#define __WIRE0_DEVICE i2c1
#define __WIRE1_DEVICE i2c0
note the mix/match, i.e. Wire0 is RP2040's IC21, etc. that's the newer behavior.
so now STEMMA QT is Wire
but the testbed scanner should scan both
@pallid grail yah, guide needs updating in a few places. STEMMA QT is now Wire and Wire1 is on SDA=24, SCL=25
my serial output above had a BME280 (0x77) on STEMMA QT and a SGP40 (0x59) on 24/25
@leaden walrus Not sure I follow what on that page needs updating. The original is in the Metro ESP32-S2 guide, FWIW. That page isn't meant to handle extra pin combinations. It doesn't use the pins to begin with, it uses the STEMMA QT connector. If you think something should be tweaked, will you consider doing it? Because I don't understand how the rest of this applies. (AFKish for a while.)
@pallid grail these pages:
https://learn.adafruit.com/adafruit-feather-rp2040-pico/pinouts#stemma-qt-3084853
https://learn.adafruit.com/adafruit-feather-rp2040-pico/i2c-scan-test
STEMMA QT = Wire
PINS 24/25 = Wire1
@pallid grail for background history, the current guide is correct for how it was at time of feather RP2040 release. however, a breaking change has since been made in the core:
https://github.com/earlephilhower/arduino-pico/pull/1468
so guide pages need updating for that
note that was done May of this year. so if you're looking at guide feedbacks older than that, those comments may or may not apply to the current setup
@leaden walrus I'm looking at all my guide feedbacks, and the only references to this are on that I2C Scan Test page.
Ok. I removed it entirely from the I2C Scan Test page, because as I said, it uses STEMMA QT only.
I will update the Pinouts page.
@leaden walrus Are Wire and Wire1 called "ports"? e.g, What does the Feather have two of?
yah, ports
Wire
Thank you
WIRE is a #def
and could be anything
#define MY_SUPER_COOL_I2C_PORT Wire
its just a name reference
Ah ok
or like in the sketch on that page:
#define DEFAULT_I2C_PORT &Wire
I'm on the Pinouts page ๐ or I would have checked that
yah, just Wire for that page
Added this to Pinouts under the Logic Pins header (down where it talks about I2C etc in CP). Is this sufficient?
I think the D24/5 designations are right, I grabbed that from the Philhower core PR.
#define PIN_WIRE1_SDA (24u)
#define PIN_WIRE1_SCL (25u)
yep
The Arduino -> Arduino
I originally had "The Feather". Good catch.
@leaden walrus Thanks for yet again sticking with me through this! ๐
@pallid grail np. thanks for updating!
Does anyone here have history using the USR-ES1 ethernet module?
Hi all. I have a weird one. Brand new Adafruit esp32-s2 feather (from digikey) and when I upload the battery state readout code from https://learn.adafruit.com/adafruit-esp32-s2-feather/lc709203-simple-data the output suggests that the battery voltage is 4.001v (or around that) and a battery percent of 99.9% even when there is no battery plugged in.
Plugging a battery in turns on the charge LED and after a reset the voltage reported is around 4v and the capacity drops to 88.4%. I believe those values are correct.
How is it possible that it is reporting voltage when there is no battery present? Is this "by design"? How would I programatically determine whether a battery is actually present?
Unfortunately you can't, the output of the charger is what's being measured there.
@lyric pivot hmm, that makes sense I guess. But I've also noticed some oddities when reading off voltages when the device isn't plugged in via USB-C, specifically it occationally reports 0v. I need to dig to find out if that simply a failed i2c read, or is it actually a the chip reporting 0.
@lyric pivot do you just "know" that it's reporting the output of the charger or is that documented in the datasheet?
Experienced similar issues in multiple other boards
Most of these linear chargers don't fully shut down when no battery is present
Some do pulse the output (visible as charge LED dimly blinking) but with any stray capacitance on the fuel gauge IC that can easily be filtered out to a low DC voltage
They'll tend to oscillate when no cell is connected, as they're designed to operate with a cell connected.
Thanks both @lyric pivot @north stream
Does anyone here have history using the USR-ES1 ethernet module?
im pretty sure i bricked my itsybitsy m4 twice, so i was messing around with compilar optmizations on my first board, it went into a state of only being in the boot mode, and not going to the run mode. After this I built a new fc and flashed my software with the compilar flags turned off im pretty sure and now its bricked again
do i need a SWD programmer to fix this
idk
i can still upload code to it and it goes through without a issue it just doesnt return to the run state
its constantly in boot mode
the uf2 thing still shows up
the cable is ok
im looking up similar issues on google and cant find anything
i think i have a fix ๐ซฐ
when i drag the uf2 file to upload the bootloader in it just ejects and i get the same issue
the file said it updated so the board still works
weird
and now i cant even upload code to it anymore
Does your itsybitsy have a reset jumper?
Gotcha gotcha. Had a similar upload issue with my Seeeduino XIAO... when the sketch uploaded, it compiled the code, re-mounted the XIAO as a mass storage device and replaced the uf2 file with the new one and reset it as normal.
It wouldn't switch to mass storage on its own, so I had to jump the reset contacts to force it to do-so.
hmm
Wasn't sure if your itsybitsy did the same thing or not.
no its different than that
Ah, that was my only guess. dang.
ok i fixxed it
it wasnt uploading becaue i had arduino open lol, flashing the new uf2 fixxed it let me try it on my old FC
This is me soldering the new fc today, nice to have a few extra on hand if I fry some so itโs not a waste of time ๐
I'm using the Adafruit Feather M4 CAN, with associated CANSAME5x library. I see in the lib that the CAN send is blocking?
Are there any hardware mailboxes I can have it populate instead?
Ah man there are Tx Buffers and a FIFO. Neither of which are configured -_-
I kinda need some help please, why does my esp32 give me this error code "E (178) psram: PSRAM ID read error: 0xffffffff"
thats the code I'm trying to run
for my rc car
I didn't write this code myself, this is from a tutorial
heres the github: https://github.com/un0038998/ESPNOW_Car
and heres the YouTube video: https://www.youtube.com/watch?v=uNXP95vOytw&t=1s
This repository contains code and diagram for ESPNOW RC Car using esp32 - GitHub - un0038998/ESPNOW_Car: This repository contains code and diagram for ESPNOW RC Car using esp32
In this video we are going to make RC Car using ESPNOW Protocol.
We will use transmitter created using Analog joystick and esp32 board to send car control commands.
Transmitter and receiver esp32 modules will communicate using ESPNOW protocol.
Car will be controlled in 2 modes, simple movement and throttle+steering mode.
I have explained in det...
Do you have an ESP32 module without any PSRAM? That's optional in some chip variants.
I have these
I have no clue if they have PSRAM
I just ordered these, but dont know if they have PSRAM https://www.amazon.com/gp/product/B0B67RRKZF/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&th=1
The listing says 4MB, which would imply PSRAM, but who knows if the listing is accurate.
there is no documentation either
I might just return them
but do you think these would work
so if you dont mind me asking, what is the point of having PSRAM
It's extra but slower memory. The CPU has about 300K built in, but for more complex stuff like cameras, you want to deal with larger amounts of data.
I don't trust anything from amazon
@cedar mountain I'd guess that 4MB in that listing is the flash size, not PSRAM
@mellow forge You shouldn't need PSRAM for that small a program. First guess is that in the Arduino IDE you chose a board with PSRAM, which is why it's complaining about not finding it. What board are you targeting the build for? the boards you linked to look like basic NodeMCU clones.
Oh, duh, good point, you're likely correct.
It is a little inconvenient that 4MB is common for both ๐
Seems Iโve busted my little oled feather. All of the buttons and the reset button work but display itself wonโt power. Any tips for troubleshooting or just get another?
run something very basic, like the learn guide for that featherwing. How did you possibly kill it?
Honestly good question. I soldered the extension pins to the bottom feather because loose connection wasnโt allowing it to work when stacked on the board. All solder tips have voltage. Iโm gonna try some extra wires connecting the i2c pins
maybe cleaning up the solder joints on the featherwing could save you. some of those connections in the image look iffy. You could try just wiping off excess on those that are blobby (use a clean-ish but tinned tip and warm the solder then wipe up the pin away from the board, then clean the tip again to remove that collected solder). Then apply a little extra, after warming the existing joint, to those that dont have a shiny joint all the way around the ring i.e. are not fully covering the rings.
Basically rewarm most of the solder connections, and re apply some solder if required (possibly removing some excess first/after).
those are the ones im using rn
for my code
well its not MY code but you get the point
it keeps giving me this error, PLEASE HALP:
E (181) ESPNOW: Peer interface is invalid
Failed to add peer
ill try that rn
and ill get back to you when I do that
untill then, time to bash my head against my laptop untill stuff happens
I understand. I'm asking what board you chose in the Arduino IDE when you build your program.
Hey, you're not dumb. I did say several things and I could have been more clear.
Further down on the Tools menu there should be an entry that says PSRAM: "disabled" or PSRAM: "enabled" - if that's set to "enabled" it should be changed to "disabled"
ok well that fixed that issue, thank you for the help and clarification
notthepotato, curious if you got the peer issue sorted
not by any stretch of imagination
I started last night at like 12:00
but then I passed out
I've got an intermittent issue with an esp32-s2 feather. This is specifically to do with the i2c occasionally dying (nothing comes up from scans) but only intermittently, including sometimes an issue that persists through a hard power down and power up... Soooooo, Am I definitely dealing with faulty hardware or could this still be a software thing?
it could definitely be a particular I2C device that is not acting polite and grabbing the bus. It's not necessarily broken hw, but could be badly designed hw (particular I2C chips)
what are the devices?
The one is the onboard lipo charger and the other is the Adafruit SHT-45. So, hopefully not a tricky combo.
do you have the LC709203F or the MAX battery monitor chip (new or older Feather)?
The LC7...
the LC709203F can go to sleep and be hard to wake up. Recent versions of its library try to get around this.
When the hang occurs, could you measure the voltage on the SDA and SCL lines? One might be pulled low.
I've read about (and tried) calling begin() repeatedly a few times to wake it up... So that doesn't fix it.... And I also lose the sht-45 so. ...
This is going to force be to learn how to use my Analog Discovery ๐
you could put the SHT-45 on a separate I2C bus, which might or might not help. (Might not help if the LC7 hangs up and you really need it.)
When I mentioned the libraries above, I was thinking of the CircuitPython library.
I've read those posts too.
I should probably just buy another board and test that below tearing my hair out.
ESP32-S3 problems, specifically. ESP32-S2 has been much more reliable
the newer boards have the MAX sensor
is the SHT sensor close by or far away?
5cm
that should be fine
I'll desolder the SHT and see if I can replicate without it.
Question on this tutorial what is pin B suppose to be? https://learn.adafruit.com/trinket-usb-volume-knob/code
A rotary encoder is basically two switches that switch in quadrature as you turn the knob. Pin B would be one of the two switching pins, shown in the wiring diagram as the encoder pin connected via the red wire to pin #2.
Not sure if that was the answer you're looking for, but hopefully that helps?
#define TRINKET_PINx PINB is the pin B I am talking about
Seems like a macro for a macro but no idea what it is
Alrighty I got a bit more on rotary encoders figured out. Still didn't manage anything really with this encoder but oh well
Hey, i have an led 64x32 display with a matrix m4 running arduino and im trying to use the imageReader library to display bmp files, However i cant seem to find a place to put them onto the m4 in order to run them. Could anyone please help me out with it.
The imageReader library is designed to read images from an SD card, so you might need to add an SD card reader. You might be able to tuck a few images into the onboard flash storage, but it would take some software hacking to be able to access them.
Ahh thank you so much, I had started to wonder if theres no real direct way considering no amount of search gave me answer.
Hey, I've got a problem with a feather rp2040 usb a host. I'm starting with the dual role hid_device_report example, and as soon as I include the SD library, nothing else, it won't compile. I've played around a bit, and I've found that it will compile with 2 out of 3 of SD.h, pio_usb.h, Adafruit_TinyUSB.h but not all 3.
If it doesn't compile, there should be some sort of error message that might contain clues as to what's going on
In file included from C:\Users\bradw\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.3.0\libraries\Adafruit_TinyUSB_Arduino\src/Adafruit_TinyUSB.h:78,
from C:\Users\bradw\sketchbook\library_test\library_test.ino:2:
C:\Users\bradw\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.3.0\libraries\Adafruit_TinyUSB_Arduino\src/arduino/msc/Adafruit_USBH_MSC.h:35:69: error: expected class-name before '{' token
35 | class Adafruit_USBH_MSC_BlockDevice : public FsBlockDeviceInterface {
| ^
Multiple libraries were found for "SD.h"
Used: C:\Users\bradw\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.3.0\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Multiple libraries were found for "SdFat.h"
Used: C:\Users\bradw\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.3.0\libraries\ESP8266SdFat
Not used: C:\Users\bradw\sketchbook\libraries\arduino_640327
exit status 1
Error compiling for board Adafruit Feather RP2040 USB Host.
Is there a Sensor that can detect when I blow on it?
Barometric pressure sensors should be able to easily pick that up.
or a microphone
Funny thing, in principle a microphone just senses rapid changes in pressure.
It looks like there are conflicting definitions for a symbol, or in other words, the libraries have an incompatibility with each other
Hmm. Think there's a way to get around that, or would I have to go into the libraries and redefine things?
I'm not sure in detail, in the past I've been known to either (ab)use #define statements to rename things, or like you said, go into the libraries and redefine things there.
Okay, thanks for the help
Is there an easy way to remove the CircuitPython bootloader from a Feather M4 Express?
links 2/3 of the way down the page to erase flash https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51/troubleshooting --> nope, that seems to be filesystem only --> maybe using Atmel Studio https://learn.adafruit.com/how-to-program-samd-bootloaders/programming-the-bootloader-with-atmel-studio
๐ค hard to tell if this bootloader will let me avoid the whole UF2 file system junk and just directly flash from Arduino IDE.
The bootloader shouldnโt be circuitpython-specific. It should be no problem to load an Arduino sketch.
The bootloader acts as both a UF2 "fake drive" bootloader and a regular Arduino bootloader. Note that if the user program crashes, the detection of the 1200baud changeup, which puts the board into bootloader mode, will not work. (This is true of 32u4 boards like Leonardo as well -- the 1200baud detection is in software.) So you need to double-click reset. It is always fine to double-click reset to get into bootloader mode before uploading from Arduino. Make sure the Port is set correctly after double-clicking.
Hey Hi all, I am new to Arduino and starting with the "Adafruit QT Py - SAMD21 Dev Board with STEMMA QT" and following its Arduino start-up guide. When I try to install "Adafruit SAMD boards" and "Arduino SAMD boards" packages in Board Manager in arduino IDE, I get error as Error: 13 INTERNAL: Server responded with: 403 Forbidden and Error: 2 UNKNOWN: read tcp 10.122.168.169:58977->104.18.13.241:80: wsarecv: An existing connection was forcibly closed by the remote host. I tried by putting antivrus down and running the Arduino in administrator mode and also PC restart, it is not working, but I am able to download other board packages, could please help out ? Thanks in advance ๐
the additional URL used is https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
from the website guide https://learn.adafruit.com/adafruit-qt-py/arduino-ide-setup
if you just put the first URL in the browser do you get a bunch of JSON back?
yeah yeah
sometimes when you install a Java program like Arduino for the first time it asks permission to change some firewall settings for it
make sure the Preferences setting for the URL(s) is not messed up.
there maybe several comma-separated URL's in there. What country are you in?
Is there a way to write to the IO registers on a SAMD51 in a similar way to port manipulation on the Arduino Uno?
Yes, but the register names will be different.
Also there is probably more configuration.
How do I find what the register names are?
I've seen some forum posts about finding the underlying code for the digitalWrite function, but I can't find where that code is on my computer
Take a look at chapter 32 in this datasheet
https://ww1.microchip.com/downloads/aemDocuments/documents/MCU32/ProductDocuments/DataSheets/SAM-D5x-E5x-Family-Data-Sheet-DS60001507.pdf
I'm just curious:
The RP2040 has alignment requirements. For example, a char can start at any address. An int16_t can only start at an address that is divisible by 2. An int32_t can only start at an adress that is divisible by 4.
Does this only apply to primitive data types like ints, char, float, etc?
Or does it also apply to custom classes I write?
For example if I had
struct foo{
char a;
char b;
char c;
}
would that struct have to be aligned in a specific way?
(I know the compiler handles this correctly. I'm just curious. And I think you can use that to really optimize memory usage)
struct foo{
char a;
char b;
int32_t c;
};
...
Serial.println(sizeof(foo)); // 8
The fact that sizeof(foo) is 8 in this case and not sizeof(char)+sizeof(char)+sizeof(int32_t) is also caused by alignment, correct?
yeah, that's almost for sure some alignment, you can maybe use __attribute__((packed)) to prevent it (perhaps other compilers flag that configuration in another way?)
great that you mention attribute packed because that's my next question! ๐
struct foo{
char a;
char b;
int32_t c __attribute__ ((packed));
};
...
Serial.println(sizeof(foo)); // 6
foo foobar[10];
foobar[0].c = 10;
Serial.println(foobar[0].c); //10
foobar[1].c = 11;
Serial.println(foobar[1].c); //11
Serial.println(sizeof(foobar)); //60
How does that work? Why does it work?
The int32_t inside foo can't be properly aligned on addresses that are divisible by 4 inside that foobar array. So I should not be able to directly work with those int32_t c.
But I can. What am I missing?
why did you use the packed on a field of the struct on not thee struct itself? no idea what that would do tbh
because I'm currently experimenting because I'm curious what packing is, what alignment is and how it works ๐
perhaps it works by the int saying "i dont mind about my own alignment" and the struct follows on that
yes but the int32_t inside that struct would still need to be 4-byte aligned, not?
i dont think so
why?
I recently did some casting of charArray[] (in flash) to int32_t and the char-Array was aligned wrong, so the char I tried to cast to int32_t wasn't aligned on a 4-byte address and it crashed the RP2040
AFAIK
the aligment is basically that processors can only read memory starting in addresses that are multiples of (lets say) 16.
if your data is not aligned, the processor will need to strip some data out of the region it read and whatnot, to read your actual information
so alignment speeds up reading information, at the cost of taking more spaces, depending on the use case you may or may not want it
but why can I, in this case with attribute ((packed)), use the int32_t. That's what I don't understand
yes. But afaik, on the RP2040 alignment is enforced. Wrong alignment = hard crash
i ran into a similar issue actually... it's an issue/bug with M0 iirc (someone helped me identify that on QMK server)
this started my journey into this topic.
i tried reading an address (which was originally u8) as u16 and it hardfaulted, eded up doing this ๐คฃ https://github.com/elpekenin/qmk_firmware/blob/pekelop/users/elpekenin/painter/qp_over_xap.c#L160-L169
great to see that I'm not alone and you had basically the exact same issue as I ๐
also... PR to which i got linked when i asked: https://github.com/qmk/qmk_firmware/pull/18612
seems like a "known" issue
i tried reading an address (which was originally u8) as int32 and it hardfaulted
welcome to the club
i ran insane on it, because my data was coming over a custom HID endpoint, from a custom program of mine running on the PC (this code runs on the keyboard), and i thought about issues anywhere but the casting ๐คฃ
i ran insane on it, because the wrong alignment depended on how long the text inside a Serial.println() was. Serial.println("sta") = by chance the charArray was aligned correctly.
Serial.println("starting") = charArray aligned wrong. ๐
"but it works on my machine"
๐
but here in this array, it's not possible that all int32_t c are aligned on a divisible-by-4-byte address. *
So why does accessing int32_t c there work?
But casting a char on a not-divisible-by-4-adress to int32_t doesn't work.
Does the compiler add some extra instruction to that foo struct? ๐ค Like "to access int32t_c first copy the 4 bytes to a different address in ram and then use them as int32_t"?
(* afaik gaps in arrays are not allowed so it can't have gaps in the array so that all int32_t c are aligned on divisible-by-4-byte-addresses)
i guess C compiler is smart enough to know that you have unaligned data on your structs and treat it properly (no idea how), but it has no clue about a random pointer being casted
yeah, that sounds like the most likely thing to me
Yes, that's what it should do. If it's not certain about alignment it can generate code which does multiple properly aligned fetches and then put an int32_t together out of them. As someone said above, it's just slower/less efficient to do it this way.
I think there is some runtime stuff going on.
https://pastebin.com/wCv1NGbs
With __attribute__((packed)) it takes 16.02 ms
Without packed it takes 8.42ms
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.
build_flags = -Wall -Wextra -Og
If you want to find out exactly what's going on you can have the compiler generate assembly code and read that to find out. You should se that the packed version is using more instructions to manipualte the same data.
now, I'm not sure why I had to make the foo finside the loop volatile. Without making it volatile it was always 0ms, so I think it optimized the entire loop away. But I thought -0g would already prevent the compiler from "optimizing something away completely"
great idea! how do I do that? ๐ค (using platformio with arduino-pico core)
Try the -S option on build_flags (not 100% certain here but that's usually how GCC works)
Because you're never doing anything with foo in the loop, the compiler optimized it out. If you passed it to a subroutine or used it after the loop it would do less of an optimization (compilers are prettttttty smart these days so it might still have done some optimization).
volatile told the compiler it couldn't do those optimizations
from https://godbolt.org (with/out the packed)
sample code used: ```c
typedef struct {
char a;
int b;
} Foo;
int main() {
Foo foo = {'a', 42};
return foo.b;
}
dont ask me what's going on there, please ๐
Just double checked, here's what I used on an ESP32 project to get PlatformIO to preserve assembly code
-save-temps=obj
-fverbose-asm```
I think I was misrembering about `-S`, sorry
yes that's it I bet
but I just feel like there should be some way to prevent optimizing stuff out for debugging ๐
Maybe it even doesn't optimize it away if I start a debugging session but I don't have a pico for debugging right now
it's definitely different and that's enough of an answer for me today ๐ฅณ
jupp that works for me as well
very nice. It also lets me see exactly which compiler options were active for each file
(verbose build, only shows which compiler options were set using the CLI command to run the compiler. But something like -Wall actually enables a bunch of options)
gcc has a zillion options... there's a guide to some of them at https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html
Developer Options (Using the GNU Compiler Collection (GCC))
there are so many rabbit holes to jump into ๐
especially once you start playing with gcc options or looking at assembly code!
now just one more question, if you know the answer ๐
Obviously here, the compiler knows that the int32_t might not be correctly aligned. And it generates specific code that can handle that.
If I'm doing a typecast from for example int8_t to int32_t, is there a way for me to tell the compiler, that it might not be alligned properly, so that it generates this specific "handles unaligned int32_t" code there as well?
I dont think so, just use a memcpy
myStruct dummy;
memcpy(&dummy, raw, sizeof(myStruct));
dummy.field;
๐ I'm just curious if there are other ways to solve this issue ๐
not saying that your solution is bad
just curious ๐
Hmm can't find anything like that in the gcc attributes https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
C Extensions (Using the GNU Compiler Collection (GCC))
Anyway. Thank you so much @lilac ginkgo @stark kindle Very interesting stuff, learned a lot
It's a lot easier to just align it.
that's what I ended up doing ๐
(no more questions for today. Just some note:
void clean_up(int* f){
Serial.println("Variable went out of scope");
}
void setup() {
Serial.begin();
while (!Serial);
delay(1000);
int a __attribute__ ((cleanup(clean_up)));
a = 10;
Serial.println(a);
}
void loop() {}
There is a whole new world out there! ๐)
I bet you can mess up a lot with these attributes
There are architecture-specific attributes too. The ESP32 has several different types of memory; you can use an attribute like IRAM_ATTR or RTC_DATA_ATTR or several others to tell the compiler (and linker) which type of memory to store a variable or code in.
C++20 bit_cast, or memcpy.
Unfortunately C++20 isn't an option for many of these environments. Arduino implementations are often stuck at C++11 or C++14..
Right but I was hoping to avoid the whole "pops up a windows explorer window and confuses my serial window" bit. Also 1/10 flash attempts crashes all the USB ports on my PC, requiring me to use the power button to reboot lol
What did you do in the end? memcpy?
I mean, you were not manually creating data, but casting something coming from elsewhere, right?
ok sure, I will recheck the preferences setting and I am in Germany
aligning it correctly ๐
It was an audio file that was converted to a char array https://github.com/pschatzmann/arduino-audio-tools/wiki/MemoryStream:-Converting-a-File-to-Flash-Memory
added attribute (aligned) const unsigned char StarWars30_raw[] __attribute__ ((aligned (4))) = { and that made it work reliably
Well that was the problem I actually had. All the other stuff around packing, etc was just curiousity. Not sure how I will use that ๐
Thats not where the problem is, tho (?)
That code is just the data in an array of u8, not casting anything yet
Problem comes at the time of consuming it
Yes of course
I was curious about such consumption
Adding alignment to the array maybe made it quite bigger?
not really. I think it just moved the start of the array by like 3 bytes
#include <Arduino.h>
#include <I2S.h>
#include <StarWars30.h>
long sampleRate = 22050;
I2S i2s = I2S(OUTPUT);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
i2s.setBCLK(26); // WS = 27
i2s.setDATA(28);
i2s.setBitsPerSample(16);
i2s.setBuffers(4, 64);
Serial.begin();
while (!Serial);
delay(1000);
Serial.println("Starting");//comment this line to make playback work.
if (!i2s.begin(sampleRate)) {
digitalWrite(LED_BUILTIN, HIGH);
while (true);
}
}
void loop() {
const unsigned char *ptr = StarWars30_raw;
unsigned int toPlay = StarWars30_raw_len;
while (toPlay > 10) {
//===Make the track stereo and quieter
int16_t frame[2];
frame[0] = (*(int16_t *)ptr) / 16;
frame[1] = (*(int16_t *)ptr) / 16;
//===Write one L+R sample to I2S
if (!i2s.write16(frame[0], frame[1])) {
digitalWrite(LED_BUILTIN, HIGH);
}
toPlay -= 2;
ptr += 2;
}
//===END
i2s.end();
}
though tbh, yes, could have also solved it in code by first moving the bytes to RAM
This was actually a test sketch I very quickly wrote to test I2S
Move to RAM? RP stores const data there too afaik
AVR's PROGMEM is another whole world
not sure really ๐ค
I mean taking 4 bytes moving to RAM, so that they start at a divisible-by-4 address and then do the casting
Whatever, it works already :p
that char Array took I think 80% of my Flash. Definitely didn't fit into RAM
Lol
How long is it
30 seconds 16 bit per sample, 22050 sample rate, mono, wav file (without header)
not sure what the original file size was
1,3MB I guess
union
i've heard the word before but I have no idea what it is ๐
oh wow that's an interesting thing
make a union that can hold 4 char or 1 int32. That ensures that the first char is properly aligned that a cast to in32 works? Is that how union is relevant here?
Yes, that's well put, and what I was getting at.
And since it's a union, you don't have to cast it, the type alias is "already there"
Hello,
i bought a brand new itsy bitsy 5v.
I can't upload any code on it
i tried to restart ide/computer i also checked the permissions (im using linux)
but i cant find the solution
The root error isn't in that screen shot.
<@&617066238840930324>
Please do not ping for help. Wait for a response, or post in https://forums.adafruit.com if it doesn't seem like you're getting a response. That is the "official" help mechanism. This is community support.
anyone got an rp2040 and come accross missing functions from stdlib like `ltoa' and 'ultoa' when building in arduino ide?
libstdc++ that ships with Arduino is often hacked to pieces. Although I would expect C lib functions to be there...
it has itoa and utoa but not the long variants
throwing errors compiling adafruit io arduino library for the rp2040 wiznet W5500-EVB-PICO.
I feel silly hacking it about to compile, so thought I'd shout the brain-trust
from the pico sdk help file.
Which RP2040 core are you using? There are a couple of them
arduino arm mbed os rp2040 latest
with pico sdk installed separately following the rp2040 vscode instructions
You could try the Earle Philhower version described here. I don't know if it includes those functions or not. https://learn.adafruit.com/rp2040-arduino-with-the-earlephilhower-core/overview
brilliant, thanks.
It is undefined behavior to read from the member of the union that wasn't most recently written.
https://en.cppreference.com/w/cpp/language/union
And we would for example write 4 chars and then read the int32.
But I guess casting from a char array to int32 is undefined behaviour as well, right? So the union is still safer/better? (aside from preventing misalignment errors)
It does depend on how it's laid out in memory, in both cases, which gets into issues of endianness and packing.
If you need guaranteed functionality across multiple architectures, you're probably stuck explicitly masking and shifting. However, if you're implementing on a known architecture, you can look at the layout and determine what's going to happen.
explicitly masking and shifting... that would be additional instructions = worse performance than just cast and pray, right? ๐
Right. Although modern architectures (ARM, PPC, etc.) are very fast at it, it still takes a few clocks to execute uint32_t y = (uint32_t) x[0] << 24 | (uint32_t) x[1] << 16 | (uint32_t) x[2] << 8 | (uint32_t) x[3] << 0;
Unless the compiler/optimizer figures out what you have in mind and realizes the current architecture will let you accomplish the same thing in zero clocks by register renaming.
You'll see a lot of this in networking code since the network byte order is standardized, and processor architectures vary
very interesting
(uint32_t) x[0] isn't that part already "sus"? What exactly is happening here?
Does that only cast the single byte/char at x[0] to uint32_t and fills the rest with zeros? Doesn't it also take x[0], x[1], x[2] and x[3] and "combines them together" to an int32_t?
Yes, the << 0 doesn't do anything, the compiler won't generate any code for that operation
Fortunately, the language specification explicitly defines what happens when an 8-bit value is cast to a 32-bit value (although it does depend on whether either or both of them are signed or unsigned, surprise)
So 0x80 might become 0xffffff80 due to sign extension
In my code I basically had
char array[4];
int32_t b = (int32_t) *array;
and that took all four bytes from the array
Which is why I generally use unsigned variable types when doing bit manipulations
Yup, that will work, but. If the array contains [ 0x01, 0x02, 0x03, 0x04 ], b might end up as 0x01020304 on one architecture and 0x04030201 on another (and 0x02010403 on a VAX)
I see
yesterday I did some fun experiments with that ๐
int64 = uint32 * int32 gives funky results ๐ Because it first does the 32bit calculation. If the result doesn't fit into 32bit, you get overflow. And then it treats the result of uint * int as uint, so it doesn't do any sign extension when storing into the int64.
(to actually always get the correct result, you have to cast the uint32 and int32 to int64)
Yes, you have to cast at least one of the operands to 64 bits first. And multiplying unsigned by signed can be squirrely as well
but funny thing is, for int32 = uint16 * int16 that doesn't apply. I think because, since RP2040 is a 32-bit architecture it does all "less than 32 bit" operations as 32 bit actually
There are performance considerations to different platforms as well. On a 32-bit CPU, storing a boolean in 32 bits is faster, since it doesn't have to promote a byte to a word before testing it. On an 8-bit CPU, storing a boolean in 32-bits is slower, as it has to check them 8 bits at a time.
Weirdly, an int on an 8-bit Arduino is 16 bits
Related question... does typecasting or static_cast<>() actually always result in any machine code? Or is that (sometimes) just for the compiler?
I mean uint32_t and int32_t are exactly the same bits, just interpreted differently.
But if I typecast from int8_t to int32_t it has do actually do something and fill the rest with zeros or sign extension, right?
In a lot of cases, there will be no generated code for the operation. But in some cases there will
And in some cases, the compiler just keeps track of the given type, and conditions later operations on it. If you cast int8_t to int32_t and then do an AND with 0x00000001, the sign extension would have been superfluous, and many compilers will omit that step.
Note that many modern architectures support that sort of thing anyway, so on ARM64, the LDRB instruction will load a byte and sign extend in a single operation.
Oops, LDRB zero extends, it's the LDRSB instruction that sign extends
Hey guys, trying to pair with a HC-05 bluetooth module from my computer. I already set the device mode & name using the at commands. It is now in pairing mode (I think) bc the led is flashing rapidly, but I am unable to discover the device on either my computer or my phone
Hello guys, I am trying to include a header file from library and when I was compiling it, it says no such file or directory.
I was working on Linux system, and first time run this code on WIndows.
I didn't change code , and it was working on Linux.
Also from the example, I can find the example the the LMP91000 library.
I think the library is installed properly, but some other reason prevent the compiler from find the file. Can anyone help me with this?
Look in arduino/libraries for it and see if the file is there or in an "include" subdirectory
the file is in the subdirctory "LMP91000" of directory "libraries".
Sorry I am not sure is it what you mean
The LMP91000.h file the compiler is complaining about, is it present in that directory?
yes
So it could be an include path problem. One thing that may or may not work (I admit I haven't bothered to research why) is to change <LMP91000.h> to "LMP91000.h" (basically quotes instead of <>) in the include statement.
Still doesn't work. But the wired thing is the compilier can locate some other file
Not sure why this happen
Yeah, you're in the Twilight Zone. Could be weird case problems, something randomly gone off into the weeds (maybe try a reboot), aliasing, etc.
Is there a reason why a falling interrupt would fail to fire on a pin while high, rising, and low seem to work appropriately? And I am seeing falling edges on a scope
On a feather m0
How fast of a pulse are we talking?
I'm trying to get interrupts from a bno085 - it's pretty fast, I think
I've tried a few pins and no joy
You have a scope, can you measure the pulse width?
they're variable but on the order of hundreds of micro to a few milliseconds
That shouldn't be a problem.
You can often set which edges an interrupt pin should respond to
Oh, ok, I just figured this out - and it's a pretty dumb one
I added a serial print in the isrs to debug and I think the printing for the rising isr was masking the falling isr.
So that's fun
Oh yeah, printing in ISRs is problematic
you can set a flag in the ISR, and check the flag and print outside the ISR
ISR should be as simple and fast as possible
Yeah, that's how I have the actual code implemented. I was just struggling to get the falling one to fire seemingly