#help-with-linux-sbcs
1 messages · Page 18 of 1
Yep, that sounds reasonable. Note that sometimes GPIOs will have a different maximum for sourcing versus sinking current.
Oooh, is that info available in pinout.xyz?
I'm not sure. If it doesn't distinguish the two values, they're either the same or the given value is likely the most conservative.
Ok, would the official raspi site be a better place to look?
Not sure off the top of my head, so I'd just be going to look there too to see. 😉
Haha I can do my own googling
thanks!
Can't seem to find any specifics on whether any GPIOs have a max lower than 16 mA, I'll just go with 10 mA to be safe
Here's a seemingly relevant table, what would Output high current and Output low current mean?
Yep, that's it. Output high current would be when the pin is providing current at a logic "1", and output low current would be when it is sinking current at a logic "0".
ahh ok
I don't see any callouts for other pin current limits, I think I'm safe with 10 mA
Yep, should be fine.
This is my first time using LEDs: I'm trying to connect my neopixels to my raspberry pi using https://learn.adafruit.com/neopixels-on-raspberry-pi/raspberry-pi-wiring
But I only sometimes get a few pixels flashing or staying on random colors
It might be: what is the 4th wire, the data's ground, supposed to connect to?
Don't worry, this is my first time using a breadboard or PCB breakout
So I hope to learn alot from guys like you too
I don't see a 4th wire there, but some strips come with separate wires for data ground and power ground. They're connected together at the strip end, but it can be useful to connect them separately to your data source and power source, so that voltage drop in the power ground lead doesn't affect the voltage levels in the data lead.
I connected the data ground directly to the rasp pi ground pin, but they all went black, or with the occasional few pixels of color
Can Lidar detect speed accurately if it is stationary?
I’m looking to use it with a raspberry pi to track car speeds
It'll depend on the lidar. Some give actual Doppler-shift velocities. Others would need to infer speed from the changing distance measurements.
Which would be more accurate?
Not sure, it would depend on the performance specs of the unit... there's a wide range of lidars out there.
Would Lidar Lite v3 or v4 work?
Yes, it looks like the v3 version has an on-board velocity feature. They quote 0.1 m/s resolution at 10Hz updates, though I'm not sure whether there's some noise on top of that. The v4 doesn't have that feature at first glance, so you'd need to do the computation yourself. It's also only got a 10m range, so I'm not sure if that'd be suitable for your application if you're targeting cars.
I don’t think you’ll find hobby lidars remotely capable of tracking moving cars, simply the velocity and range limits alone. A car at even low speed can move through the field of vision faster than 100ms (10Hz). And Lidars aren’t generally fast enough anyway. You’ll really need a proper field radar to deal with car speeds, and the ability to deal with multiple cars, echoes, etc.
You mean a field doppler radar thing? I was kinda drawn away from those because of the low lifetime on some of them
Yes, those. They’re fast enough to capture a moving car, by design. Until you get to that level of performance a car is generally too fast and too far away for hobby lidars
Is there something like a fan stand for raspberry pi 
I wasn't able to find one.. I read on a few sites that a good place to install a fan would be one where the fan faces the heat sink so the heat sink is cooled, which makes sense from a logical standpoint and is what I'm trying to do
but i can't find a kind of stand that screws a mini fan in such a place.. for now im resorting to duct tapes
I've not found that the specific location of a fan makes a huge amount of difference. Even just stirring up the air near the Pi will have quite an effect. That said, I have one of those tiny $3 box fans and I just blow it into the area between the Pi and its HAT, and that drops the temperature down quite significantly. As to mounting, I cut a small bit of "L" shaped aluminum and just mounted the fan to one of the HAT's mounting bolts. Nothing fancy. I wouldn't use tape on anything as the glue will eventually start to gum up the works. Electrical tape is the worst, but duct isn't much better. Unless you're pushing the absolute limits of your Pi any fan will do.
That's a very conveniently-shaped piece of aluminum 
I bought a meter of it at the hardware store for about five bucks. A hacksaw, a drill and maybe five minutes and you're set.
Same with that bit of aluminum holding up the TFT display. Same idea.
Is there a good raspberry pi compatible pulsed radar sensor that isn’t too expensive? I noticed the only one i could find that isn’t out of stock or discontinued was around $250 total.
If you're talking about motion detection there are radar sensors in the under US$5 range. For doppler radar units capable of measuring cars, well, I won't pretend to know the answer but even the little I do know about them I'd guess they'd be pretty expensive at minimum, $250 doesn't sound remotely unreasonable to me.
But it comes in two parts, one is the actual pulsed radar sensor for around $50-60 and the other is the raspberry pi shield/hat for $200
Which seems to make no sense as to why it’s so expensive
This is the Acconeer XR112 and XC112 combo, I'm guessing? It looks like they also have an XM112 and XB112 combo which is more of a simple breakout board instead of a hat form factor, but it is cheaper.
Note that they say the range is only like 10m on that radar chip, I think.
I think I found a better solution that doesn’t use the Acconeer sensors, instead using either TOF or IR distance sensors. It acts like those speed detecting strips on some roads but instead using distance sensors on the side of the road.
Adafruit has some IR distance sensors with 5 meter range which should be good enough considering this might be right next to the road
The problem with these 5m and 10m ranges isn't that it can't see a car. It's that a car at speed needs to be within the range for several iterations of the sensor's capture, so simple math will tell you that a 5-10m sensor running at 10Hz might not even notice a car going through at 60mph/100kph (27m/sec). You're going to need something more like 50-100m range to work with cars at speed in order for it to have a chance at an accurate reading.
Just by comparison, some police lasers operate at 600m-1km, with X-band radar guns operating at up to several miles away.
Would this work at a high enough speed? I don’t know the refresh rate of it. https://www.adafruit.com/product/3978
What is the closest thing to a LiDar or iTOF that I can get for a raspberry pi on this site is?
And you can probably help, I need something good enough to detect a wall in active time
What kind of range do you need? If it's up to a few meters, there are a number of options, but long distances get more complex.
is actual lidar ok? not sure what "closest" means?
https://www.adafruit.com/product/4010
also numerous time of flight options as simple i2c breakouts:
https://www.adafruit.com/category/689
iTOF is slightly different from the TOF sensors Adafruit carries, it uses phase shifts instead of time to calculate distance. It's used more frequently in 2d arrays for depth mapping, as it's capable of higher refresh rates in exchange for sensor and software complexity.
That being said, most distance sensors are more than enough to detect walls and similarly large obstructions with high enough response times for most robotic applications. Is this something that has to move or respond to high velocities?
Can I take the SD card from my Raspberry Pi 2B and put it in my 3B+ and expect it to work like it did with the Pi 2B? I can’t get 2B’s any more and it would be nice to have a backup spare just in case something goes wrong.
maybe
if it's an older version of pi os, like pre-dates pi 3 release, then no
but could try doing a dist upgrade before transferring sd
but also very easy to just start over with newest os release images
latest releases work with all models at that time
OK, thanks. I just have all my custom code, LED matrix hat, etc. running on the Pi2, so starting from scratch is way more complicated than (hopefully) popping the SD card into the Pi 3. 😉
I suppose it wouldn’t hurt to try after backing up the card.
Always back up first 😄
Well I am making a virtual room for VR navigation called the “Full Guardian Field”
Basically its callibrated with “Anchor Plates” to generate full walls with one plate acting as an origin point
The end goal is to create a product that creates and saves an entire environment inside the house
But for the VR devices to use
one with the headset my team is making and one without, utilizing a DIY Pi to create such an environment
If the "wall" is virtual, that's a bit different than detecting a real wall that can reflect real light.
Oh, that is an application that requires some degree of real-time depth mapping...
I believe he's using real surfaces as points of reference for his VR environment
If this is a question about trying to find a Time of Flight sensor to measure the speed of cars, I'd say no. You're really operating against the limits of physics. Any of these Time of Flight sensors aren't really suited for measuring fast moving objects, both because of range and sample speed, but also due to their nature. They are designed to reflect a pulsed beam of light off of a relatively static object to measure distance. Even putting a ToF on a servo and rotating the servo too fast will mess up the results. They're not doppler devices.
Ok, I don’t know what Doppler radar I should use then, the DigiKey A111 is discontinued.
You know, I'm not sure if Adafruit offers anything at the level of depth mapping you're looking for. Those applications, if I'm understanding what you're trying to do, use much more advanced components than you would expect from a hobbyist project today. If you're developing a product for market, you could look at some development boards like this one: https://www.digikey.com/en/products/detail/analog-devices-inc/AD-FXTOF1-EBZ/14290452
The device will be fairly close to the road by the way, the person I’m working with says it might be mounted to the bottom of his mailbox.
Order today, ships today. TR-EVO-60M-EVAL – TR-EVO-60M series Light, 3D Time-of-Flight (ToF) Sensor Evaluation Board from Terabee SAS. Pricing and Availability on millions of electronic components from Digi-Key Electronics.
That is correct, I made an application that requires a ruler of sorrs
Good idea, the base right is a hobby project to teach others on how to make a self generating field based off image recognition, so im being tossed a few directions like 3 iTOS with a dot camera
If you're looking to measure the velocity of cars on a road, and you can mount sensors on both sides of the road, a pair of long-range breakbeams can determine velocity based on the timing at which the two breakbeam sensors detect an obstruction. It doesn't work when two cars pass simultaneously from both directions, but it's a much more cost-effective solution for reading velocity on a fixed path.
Actually, my brother's senior project was basically two load cells at a fixed distance to measure the velocity of cars in a lane, if I recall correctly.
Not that I would be able to recommend something to put in the road that's safe to drive over, since I think his pads were custom-made with optical fiber or something.
You could also mount two ToF or other high-speed distance sensors aiming at an angle downwards from roadside, perpendicular to the road, effectively acting as breakbeams. Then measure the time difference between their trigger timestamps. That effectively solves the multi-lane problem as well. But mechanical is still probably better (simpler and cheaper and more reliable) than anything else in this regard, and just two of those pneumatic monitoring tubes (the black cables used for counting cars) would work fine and are demonstrably safe, can handle vehicle weight and likewise motorists are familiar with them.
That would only be bad if it was at a mailbox
I can only put stuff on one side of the road though, and it’s a two-lane road
It also cant touch the road
That’s what I was thinking of, two TOF distance sensors and when they detect a change in distance it’ll calculate the speed of the car from the delay between the sensors triggering.
I have a pi with several .py files on it, how would I go about figuring out which file is set to run on startup?
unless you set something up, none are
Ah this is someone else's project, so they would have set it up
then it'd be whatever they setup. got any more info?
Not a ton, I was hoping there was an easy way to determine this. What info would I need?
generally knowing what they did. used sysv init? systemd? crontab?
are the .py files part of some larger package? or just a collection of individually created .py files?
Seem to be just a collection of py files, haven't had a chance to go thru them
This is a capstone project so I have a report, but my reading so far leads me to believe it's very incomplete
can I ask "idea" question here?
You can ask any question that is relevant and G rated!
I'm aware that Arduino doesn't have the power for things like navigation, and I've seen many ppl use Pi instead. My idea is as follows; Pi device that will read a map (it has to be an offline map) and give some kind of warning when a preloaded GPS location is reached. Device could be battery powered, but since I plan to use it in the mountains, internet use for maps is irrelevant
so a GPS device (dongle?) can update the Pi every second with a location, and once it reaches a certain GPS location, or a zone, it gives a sound or something.
I'm looking around on youtube for "raspberry navigation" but I haven't bumped into proper project, I did try to look up "raspberry pi navigation boats" and it gives some chartplotting projects, would that be close to what I'm after?
is your navigation just based on proximity to the preloaded location?
warning when a preloaded GPS location is reached.
that could be done on an arduino
like this:
https://learn.adafruit.com/flora-gps-jacket
Yeah, handling a full map is difficult for an Arduino, but computing the distance between your current GPS coordinates and a reference location is much easier.
I can't find hide nor hair of how the students set up the pi to run a program on start. Is there a process I could use to figure that out? It's ok it's painstaking, I'm hourly.
You could corrupt one of the .py files with a syntax error and see if anything shows up in the system logs to give you a clue what might be running it.
but...it's just a preset location, a gps number, and Arduino can take in GPS data and see if it's close or not.
geez...
I'll look into it.
How would I check the system logs?
dmesg | grep changed_filename.py for a quick/easy look
does the project have any kind of install and setup instructions?
Ha, not really. Not for the software
So the process would be to alter a py file so that it has a syntax error, then power cycle the pi and run
dmesg | grep changed_filename.py in the terminal?
worth a try at least
ok! I will try that
how did you get the .py files onto the pi?
ah let me lay out the situation in more detail
2 student teams made 2 projects for my work. So I didn't get the py files on there, they were already on when I was hired.
and not backed up ha
I'm a new hire to refurbish these two projects as well as to take on new project ideas they have, since they got poor-mixed results with hi costs from capstone projects at our local university
which TBH makes sense, I wasn't that emotionally invested in my capstone project
are you on one of those pi's right now?
those warning are being shown?
yes
but the pi is not in range of wifi unfortunately so I can't ssh into it, but the students were nice enough to include a mouse, keyboard and monitor
ok, so you're logged in as regular pi user?
seem to be
where are the .py files located?
on the desktop
know how to open a terminal window?
maybe? try it. i've never used pi in gui mode.
you should get something that looks like when you ssh in
i have a window with pi@raspberrypi:~ $
cd Desktop
done
how many .py files are there?
4
pi pi
these have been currently setup to auto run? so they are running now?
I assume
I've been dealing with printer problems all morning and haven't looked at the codeyet
ps -ef | grep nameoffile
change nameoffile to name of one of the files
can leave off .py, and doesn't have to be full name
just enough text to match
for my edification, what are these commands doing?
listing all running processes (ps) and then only showing ones that have matching text (grep)
ahh
does it matter if the filename has spaces?
the file is 0 everydoor opens until end.py
use everydoor
ooh ok
ps -ef | grep everydoor
ah right GREP is regular expressions right?
it uses those for the pattern matching
Ok I'll try the other 3 and get a pic
go through same check with other files
For the file 1 short music light show.py
and for the other 2 files, these look like they are not running
yah, doesn't look like anything is running
this is a crude check, but doesn't look like
can test functionally? like whatever the project is supposed to do - is that currently working?
can you describe?
Totally
I don't know that this diagram is accurate to the actually installed system, but it's what I have to work from
It's an advent calendar with some motors and lights
pretty yuge, easily 12 feet x 20 feet on the facade
is there any user interaction involved?
have you looked at code in the .py files?
check if they have forever loops, or are more like run once to completion
if later, then they may be set to just run daily, like via cron
which is why they don't show up as currently running
Ahh ok, I doubt it's a chron job, the pi is being used how you'd use a "dumber" MCU like a SAMD21/51
Which is how the file system for the other pi for the other project got corrupted, incidentally. Improper power cycling
do you see forever loops in the files?
I'm picking up lunch ATM, on my phone but I'll check when I get back
ok. check that next and report back.
that info will give some clue as to how these were meant to be used
Will do, appreciate the assistance
is RPi.GPIO a built in rasberry pi library? This code was written in ~2019, was Blinka a thing then?
Yeah, none of these have while True: loops
@steady rose would it be useful to run the command
ps -ef | grep .py
?
rpi.gpio may come preinstalled these days? not sure.
but in general, it's just another python package.
blinka uses it under the hood
ahh ok
are there any import board lines?
Yeah there are a number of ways I want to improve this code, but I need a MUCH better handle on the electronic hard ware
No there are not
then probably not using blinka
it's using RPi.GPIO, time, and pygame
that's fine
I think only one of these files is supposed to run at any time, I think they give you options for functionality
there's nothing but digital IO going on (pre the schematic)
so using rpi.gpio is fine
is board better if you're doing SPI or I2C/S ?
sort of. it's really more if you want to use circuitpython libraries.
makes sense, I thought they were using shift registers but I see no evidence in the code
like if you had a SPI or I2C breakout board
and wanted to use that in python
on the pi
then you'd want blinka
if you're just setting digital pins high/low
can stick with just using rpi.gpio for now
are you still at the pi?
crontab -e
burritotab -e more like.
run that and see if there are any entries
twice now when I've pressed CTRL on the keyboard attached to the pi to wake it, it has seemed to stall/restart the music. Coincidence?
do I need to be on the desktop?
in terminal, same as running the ps commands
what's the same?
same as how you ran the ps commands
in a terminal window, which will be "on the desktop" i guess
scroll to bottom of that file
after all the lines that start with #
there may be nothing there
last line of header comments is probably # m h dom mon dow command
ok. nothing there.
So they aren't using cron?
doesn't look like
Hmm
at least not as pi user
does the calendar do stuff? like whatever is plugged into all those relay controlled outlets?
Yup
It runs through a 5-10 min program playing music and switching relays
how often?
have you rebooted the pi at some point ever?
Yes
and it when it comes back up, it starts running the calendar?
Seems to yes
the calendar is currently doing stuff?
It's currently informing me of a Holly jolly christmas
<CTRL><X>
'4 low current.py'
ooooooh, well I know one problem
This monitor it's hooked up to has burned out spots, so I can't see the full desktop XD
how big is that .py file? like how many lines of code?
trying to find it
actually. nvm. the pi isn't connected to discord, so can't upload it here.
at least open it up and take a look at the contents
through a marginally awkward process, I can
give me 15 minutes or so
I have to find a drill to open this enclosure
wait. not yet.
can just open it there and look real quick
more 4\ low\ current.py
run that and take photo
It's too long for a screenshot so I plugged in a USB drive. But there's no button for ejecting it...
Figured it out one sec I'll upload the code
is the pi connected to internet? could curl it up to a pastebin.
I have wifi on my laptop but not on my phone, I think the pis wifi chip doesn't have have oomph
ok, nvm. it'd be the pi that would need to be internet connected.
Yeah
here's the code
I don't like the amount of time.sleep()s in this codebase but it works so I don't want to mess with it
it looks like it will loop 400 times and then exit
interesting
but that's probably what is currently setup to "auto run"
it's using a feature of the desktop ui
guessing you can just drop stuff in that Autostart folder and it will run when the desktop is launched
"good way" is matter of opinion
same for whole code setup and approach
Huh, I guess I could try that, is there an easy way to just display some blinking "lights" on the desktop so I can remove the existing code and put my test code in?
Yeah, I don't love it, but if they were in the same degree program as me it's possible their only coding experience was MATLAB
try this, if possible, move the file out of the Autostart folder and then reboot.
see if it then does nothing
totes possible
let me do that real quick
software reboot OK? or do I need to turn off, cut power, then plug power back in?
soft reboot fine
could probably also just log out of desktop / back in
but best to just reboot to be sure
I've confirmed that when I wake the pi, it interrupts the music for a few seconds. Is that a pi thing or an artifact of the code?
pi thing. it's just hiccuping when it comes back up.
ah ok
It's not a problem for our use case
OK, pi restarted, a bunch of relays are clicking
motors are spinning
but no music is playing so I think the code is not running
yah. probably not.
no idea why the relays were clicking on and off, that's unusual
what action you are seeing is just from pins state changing by booting
ahhh
once up, it should be stable though
it is
it seems they didn't use a 74HC595? The code makes use of 25 GPIO pins
so how would they have setup the autostart program, and would you recommend something else?
they just wrote that 4 low current.py file and plopped it in that directory
is that a default raspberry pi thing? A folder on the desktop named Autostart will run whatever is in it??
not sure. i've never used it.
but seems like it's an easy way to provide a "run at launch" feature
but i think we've discovered how your current setup is working
I do too! Really appreciate your assistance
np. what you do next is up to you.
should the code be different?
i dunno. ask 5 people and you'll get 13 different answers.
same for best on how to autorun
I personally think it should be more elegant, but I don't have time before the deadline to mess with it
then don't
unless you know now what needs to be done
could burn unknown amount of time going down various rabbit holes
another thing you can try - change the loop count to 1 and put the file back in Autostart
it should then run only once through
I can't see why we would want it to shut down after 400 runs but what do I know
that makes sense
ok. good luck. i think you've got a better idea of the setup now.
really appreciate it!
related, I found a guide for adding a pushbutton that shuts down the pi safely by shorting two pins together, any idea if that method will also wake the pi assuming power is connected?
depends on harware setup. i think to wake, it would need to tie into the run pad, which is not part of the 2x20 GPIO header.
powering down could be a simple script that calls shutdown when a GPIO pin changes from attached pushbutton
Is there a way to assign a GPIO output to a block of RPI GPIO pins in python in one smooth write the way you can mess with registers in an arduino?
Ah it seems there is, but I suspect it just uses a loop
although idk whether or not arduino can truly do it simultaneously either, FWIW
Arduinos normally have the I/O pins in "ports" which are accessed as registers on the chip, so groups of them can be accessed simultaneously in parallel. I suspect the Pi has a similar architecture, but things are normally done at multiple levels of abstraction, so I'm unsure if there's a way to get at the chip registers directly without messing something up.
trying to setup a simple pushbutton on/off on an RPI. The guide I'm looking at uses the RPI Zero W, the pinout there is the same as other 2x20s right?
yep
that looks like GPIO3 and gnd
and says to connect GPIO 5 and 6 to the button, but on pinout.xyz 5 and 6 are not there
no but it is physical pins 5 and 6
ahhh
so that might be what they mean
I should let them know that that's confusing
there's wiringpi numbering also. each pin has (at least) 3 different designations. 🙂
does that guide say the button can power up also?
It seems to yes
can you link to guide. curious how they are doing that.
One sec, at a staff meeting :)
sure. np. whenever is fine.
@steady rose . it's this one https://scribles.net/adding-power-switch-on-raspberry-pi/
ahhh
is power on/off possible?
I'd like to use an illuminated panel mount LED
and have the illumination be only when the pi is truly on
There's a Pimoroni SHIM that does it. https://www.adafruit.com/product/3581 You can use it with other things on the header. Though with a MicroB adapter on it, it's only compatible with Pis that used USB Micro for power, I assume.
That's probably not what you're looking for though.
Oh: "It's possible to use OnOff SHIM and a 2.5A USB micro-B power supply to power a Raspberry Pi 4. However, the recommended power spec for the Pi 4 is 3A, so you may run into low power issues (especially if using power hungry USB devices)."
Might be able to bodge on a 3A Type C connector if the other components are up to the task
I think the C connectors are different enough from the Micro that it would not be even close to a simple task. But I don't know for sure.
I think there are some breakouts that would make it easier, but certainly not something you can just plop on that board
@civic rune as mentioned / linked from that guide, powering up requires additional hardware. but there's no one specific arrangement. so there are various options out there. the lowpowerlab linked from guide. the pimoroni shim linked above, etc.
one easy option - just add a toggle switch inline with the USB power input, like this:
https://www.adafruit.com/product/1620
you'd use that other guide to provide a safe way to run shutdown, with the button attached to GPIO header
you'd want some form of "shutdown complete" indicator, could maybe use LEDs on Pi
but when shutdown is complete, then kill power via that USB switch
to power back up, just turn switch back on
http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/electronic-circuits/push-button-switch-turn-on/latching-toggle-power-switch
For some reference circuits for power switching similar to a PC power button, this has some nice soft latch switch designs using NAND gates or MOSFETs to switch the DC main power to a device. If you can break out the 5V from your supply to a circuit like this, you could power on with hardware, and shutdown with software or a long press.
Application note for electronic latch circuits using logic gates and MOSFETs that detect a push button press to switch ON power to your embedded system. Because their MOSFET switches consume no current in the OFF state, these circuits are useful for battery powered portable instruments. A momentary button press turns a power MOSFET ON, and hol...
maybe this also?
https://www.adafruit.com/product/1400
This would be good to turn it off after it shut down and to turn itself back on again, but you couldn’t use it to have the pi shut itself off because the Pi wouldn’t be able to send a kill signal by the time it was safe to turn off. But an MCU with some delay might do the trick
JP talked about it in his Pick of the Week this week, actually
yep. it'd need to be used in conjunction with the other switch.
and modify the script to run shutdown and also signal that breakout to kill power
Yeah. Complicated, but doable
At that point, you may as well use an adapter instead... https://www.amazon.com/ARKTEK-Adapter-Charging-Digital-Samsung/dp/B072J5B3BR
Not sure if the Micro connector can handle it
Don't want melties
I love all this conversation about my problem, thanks folks!
So with my existing setup, I think just a power off button is fine, people can unplug and replug the cable for the power supply I'm using (https://www.digikey.com/en/products/detail/mornsun-america-llc/LM25-23B05/13530997). If I have an LED button with the LED tied to a GPIO, will that only be on when the device is powered? Or could I add something to startup/shutdown to make sure that the gpio powering the LED is in the right state?
You should get a power supply capable of 5V/3A, or your pi may complain
assuming it's a pi 4
that's always a good idea
Case depends on what you want to do. I don't know if there are cases available that expose the GPIO header
But if you're just hosting discord it should be fine. I don't have a pi 4, just a 3 A+, but getting discord to open on it was impossible
IDK if an official Discord app would work better than the browser
doesn't sound like it
Samsung EVO SD cards are cheap and good. There's multiple types of them, the green ones are the ones I get.
You could get a heatsink case as well to help deal with heat if you're running it hard.
But if you're only doing software stuff, you don't really need any other additions other than what you listed.
Oh!
Depends on how large your website and bot are going to be. 4gb is more bang for the buck, but I’d recommend 8gb for anything you plan to take public.
For setting it up, you need to either do some shenanigans to get it connected to your network so you can get into it, or you need the right HDMI cables, a display, a keyboard, and a mouse.
Yeah, that's what the shenanigans are for.
Simply making sure you knew those were your options 🙂
You can. For a headless server, display and peripherals would only be for accelerating the initial setup.
Or VNC
That will absolutely work.
Keyboard and mouse, USB, or one of the wireless-type ones that has a USB dongle will work.
Otherwise, do the setup needed to run it headless, and you can SSH into it to do whatever you need to do.
For a server, you’re usually not using a ton of usb devices.
No but say you wanted to use a mouse, keyboard AND a USB stick for something, you'd be outta luck without a dongle
A fan and heat sink are highly recommended for long term use
what if you're not doing hi intensity stuff?
I think 8GB is the min
Yeah smaller ones get more expensive as bigger ones get cheaper. 🤷🏻♀️
I think the elves that make them get annoyed when we make them do the same amount of work for less storage, so they punish us by charging more
For setting up server, seems pretty normal
yes
my Pi 3 A+'s wifi chip is around as powerful as my phone's
No where near my laptop's
here powerful is measured by distance from the AP you can go before losing signal
Does having a py file that runs on start (method as yet undetermined, happily will take advice), interfere with any methods to have a shutdown button?
as in can you have a file running on start AND a shutdown button method?
Yes, depending on how you set it up you make the pi spawn multiple processes on startup. One can be your button listener, and another can be your startup program
That's an option, but depending on how to tell the pi to start the program you can also just tell it to "go to this folder, start this program, then go to that folder, and start that program"
that way you don't need to mess with threading and you can let the pi handle the messy bits
Interesting, what "messy bits" does it handle?
I'm not opposed to a little light multithreading, I've always wanted to get into it
the multiprocessing/multithreading. I try to avoid threading when I can personally
So one program would be my main.py file, and the other would be the shutdown script. How do you make the pi run them both at once without threading?
Is there an ISR like thing I could do?
Kind of like opening two terminals and in one terminal running main.py, and in the other running the shutdown script
ISR?
Interrupt Service Routine
ahh. I'm sure you could, but you don't need to get that into it. How are you starting the scripts on startup?
I haven't decided yet, I "know" enough about one method that the team who worked on the product I'm working on used to google it, but I don't know if it's a "good" method. They have a folder called Autostart on the desktop that has their file in it, it seems something is going on to cause the pi to go to that folder and run the program
have you looked to see if they've got anything in /etc/rc.local?
You can display the text of it using, cat /etc/rc.local and it'll show the text of the file on your screen, and if you want to edit it you can use nano or any editor of your choice (but you'll need to be root to save files, so my workflow is sudo nano /etc/rc.local when I edit it
I had to get some laser cutting done today so I'm working from home and don't have access to their pi but should I just be in a normal terminal to run that?
yup! That'll do.
perfect!
Oh I should be clear, I'm working on 2 systems, one of which is from scratch. The from scratch one is where I want to have the shutdown button
I use /etc/rc.local to manage all of my 'run on startup' files. There's a few hiccups it causes though--like it's running the files as root not as your user, python programs you installed might error because it can't find them. There's a solution to that--tell python to check the folder that the python modules are installed in--but it's a hiccup none the less.
I have a webserver and an alarm clock running on this specific pi, both are two separate python programs that are told to run on startup from the /etc/rc.local file
I'm using Blinka and an adafruit library, would I need to figure out where those are stored?
I only run this pi's on a trusted network though--I'm not sure about how safe /etc/rc.local is on a public network. I've never found a clear explanation to that end
I think so
If we're on a network at all it will not be a public one
But I think both these pis are out of wifi range anyways so "hacker proof"
he says knowing it's not true
Ok that's good. I just wanted to highlight that I don't know it's security that way if it was a critical system you could look for a different solution.
I wish I knew more about securing things, but I can at least know when I don't know
Only thing I can think of that someone malicious could do would be to turn on a bunch of SS relays, but people would notice the odd behavior that creates
I think I had to install these libs with sudo, does that help?
If that's the case, I believe python should be able to have the path without issue
ok I can test that soon with a simple blinky program
And if it can't find them, we'll adjust the start of the python program to import sys, then on the next line run sys.path.append("/path/to/pymodules/"), and it'll work
oooh
I just love python so much
I love my mom a LOT, but python is edging uncomfortably close
Python is pretty powerful. It has it's hangups and areas I hope it gets better with, but it's a pretty great language to work with byinlarge.
I love the development speed
That's the part I'm in love with as well, circuit python brought that rapid development to microcontrollers for me and it's just been a joy getting back into electronics
I LOVE circuitpython
I have to leave it behind next year for a project that's ill suited to python and I'm devastated
That's generally more a function of the antenna than the chip.
Oof. But it'll give you a chance to learn something new, that's always a nice thing
Before we do get too far off topic, I just wanted to make a note about the /etc/rc.local file.
An empty rc.local file should look like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
Inside of it you basically write the commands you would in the terminal in order, as if you were just navigating to your directory and running your file:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
cd /home/pi/Documents/myPrograms/
sudo python3 my_program_1.py
python3 my_program_2.py
exit 0
To run multiple programs, you can have them on separate lines, just like your terminal history shows. But if you do it just like shown above, my_program_2.py will wait for my_program_1.py to finish and exit before it starts. To get around that, we'll change the line by adding a & at the end of it--it'll let the pi run the program in the background so you move on and run the next line in the file (https://unix.stackexchange.com/questions/86247/what-does-ampersand-mean-at-the-end-of-a-shell-script-line)
So those lines will look like this:
cd /home/pi/Documents/myPrograms/
sudo python3 my_program_1.py &
python3 my_program_2.py &
When changing directories in the rc.local file, I like to use the absolute path that way I know exactly where I've changed the directory too by the way. That way if you go to a bunch of files, you're not stuck in a position where you need to mentally keep track of where you are
I support this methodology, it makes the most sense to me
Additionally, this might help in understand the different ways you can start a file on startup: https://stackoverflow.com/questions/36375647/what-is-the-difference-between-etc-rc-local-and-bashrc/36376898
I see in your examples you don't run sudo twice?
One of the files doesn't work without sudo, the other does. I don't remember if I just added sudo because I needed it when I was running the program manually, or if the /etc/rc.local file needed the sudo
It's an alarm clock program that changes the lights in the room to a nice blue in the morning, so I just got it to work and didn't look back 🙂
makes sense!
I figured I'd keep the sudo in so if you were running into issues you'd be comfortable giving it a shot
I should also note that because we run the programs here, you won't see any output in the terminal. It'll just fail really quietly.
So it helps to create and save logging files
I'm planning on testing it the way I would a CP project, so hopefully iron out the bugs
i am very sad... i tried to remove the soc from a pi zero
and the ram on the top came off 1st
tried to reflow it back in place
but no luck
What does the soc look like without the ram?
bare chip in the centre, solder pads around it to fit the ram
Need some C wizard to glance my code if possible. Here's my project page (still a work in progress but you can see it's getting there): https://github.com/karikuiv/Hydroponics-system
Been out of work for a while and I realize I don't have much experience especially with 'real' software tooling and environments but it's time to start getting paid again.
What should I do better regarding the code quality (or anything else) to get a job in say embedded c development in a junior or even trainee role, or at least interviews?
It looks like nice neat code, but I'd wish for more comments.
Thanks. Do you mean like explaining a little better what's being done per function or per component/file?
Yes, I also like to have comments explaining what each variable is for
Does Doxygen do C code?
Thanks and I'll also look into doxygen
I've only used it for micropython, but I think it works for at least C++
Not sure about straight C
Yeah, it works for C too, since the syntax is basically a subset of C++.
ahh cool, I suspected but didn't want to give bad info on the internet, we know how rare bad advice online is 😛
when making a hat for the pi, I should connect all the grounds to ground and 3v3 to 3v3 and 5V to 5V, right?
I dont want to assume they are connected internally
Here's what my header looks like
ok not sure if I should ask here or arduino about pi pico
going here
I am trying to interface a pi pico with a ebyte e32 module
That's a LoRa radio using a Semtech chip, right?
I believe so yes
Seems to just have a UART interface, so there shouldn't be any trouble interfacing to it with a Pico from a hardware perspective. Just a matter of the software driver.
its one of those lol
I believe that I have it connected correctly
but my problem is software
I cant find any tutorials for that.
And I seem to be missing some modules such as SoftwareSerial.h
No idea there, I'm afraid. I'd just be Googling for it too, to see if anyone published a library somewhere.
If you have the pins available, you probably would prefer the second hardware serial port on the Pico.
ah. I can move to that one for testing. I will ultimatly likelly need only 3 of the 5 it has
I assumed 0 would be the default first
would you recomend I go for micropython or arduino?
it appears theirs not much info for either but slightly more for micro python
problem is no such gurantee with any of the other modules i need
Yeah, I couldn't really make that call, since I don't know your relative comfort with C versus Python, the state of the various libraries you might need, or even what your overall project is about.
I just meant in a general sense. Micropython looks promising but idk where it is as far as support goes. I know both C and Python with about the same limited level. Project is basically throwing a bunch of sensors in a solar powered box and transmitting the data to elsewhere
I'm just not sure, I'm afraid. The Pico is a relatively new chip, and I haven't worked with it myself yet, so I don't know the general state of support. Hopefully someone else can chime in.
What sensors are you using?
Well good question. the temp envoronment sensors I ordered got lost in the mail and the gyros I ordered ended up being the wrong fcking kind
so I will probably decide in a bit.
I will also be making another lora device with a GPS sensor
as a tracker
I got 3 of the transciever modules. 1 will be a perminant deployment solar powered weather station (if it goes well I may make more), 1 will basically be a gps tracker and the last, of course, will be used for communication with the other two
I had wanted to interface it with the adafruit ftdi usb thing I use with a thermocouple but I dont think that will work from a software standpoint
idk perhaps. I run linux on my laptop so I guess it would kinda just be like using a raspi...
I'm working on a project with altimeter sensor & pi zero w waveshare e-ink screen. I have the sensor data writing to the screen but I'm not sure how to keep it refreshing as the data is updated. I know there's a way to do a partial refresh so i added the clock example code and put the altimeter temp output to the screen within the loop but only the time is updating and not the sensor data. If anyone is willing to help me w that, lmk.
It'd probably be useful for you to share your code via pastebin or something.
Np, was actually cleaning some stuff up in it and I'll share ty
got it working with making the sensor ouput into a function instead of calling the variable, i updated it here https://pastebin.com/ZL6qZVG3
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Could I get a 128x64 monochrome OLED display to work on the QT PY 2040? I just need to draw shapes to it.
Yes.
Alright thanks
how do i wire the SPI touchscreen on this tft to a rpi 4?https://www.adafruit.com/product/2050
i checked this and the wiring only includes how to wire the display only, not the touchscreen too
oh.the ts. hmmm...one sec.
since it's just the "raw" pins for the touch overlay, you'll need to use a controller of some kind
Y+ X+ Y- X- these are the 4 resistive touch screen pads, which can be read with analog pins to determine touch points. They are completely separated from the TFT electrically (the overlay is glued on top)
something like this:
https://www.adafruit.com/product/1571
as an example, you can see how the HAT version of that same TFT includes a STMPE610:
https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi/downloads#layout-and-schematic-for-pitft-plus-3-dot-5-2037253-2
but also...not seeing what is the suggested replacement for the disco'd PID 1571 breakout.
ive only seen touch screen controllers used only on microcontrollers, not sure if they would work for a rpi
The reason for this is the lack of analog-capable pins on the RPi. You can certainly implement a resistive touchscreen if you add some sort of ADC to handle it. https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters
Alternatively, if you want something even easier to use, here's a touchscreen-to-USB breakout board. https://www.adafruit.com/product/1580
You can calibrate your screen with a windows pc, then just connect it to your Pi's USB port.
Yay for plug-and-play convenience!
so no drivers needed?
Not to my knowledge.
Yeah, I've been trying to connect these extra touchscreens from work to a Raspberry Pi myself, but I never got around to playing with the touchscreen interface on it. Pretty much all of the Adafruit display breakouts use the AR1100 chip to handle the resistive touchscreens in what I think is the easiest way possible, but I've been working with capacitive touch...
So until I get around to acquiring a proper breakout for the 6-pin FPC tail, I'm gonna hold off on that. Luckily, he capacitive interface is just I2C so the Pi can handle it. Unfortunately, the Kippah took the I2C pins away from me, so I might have to spin my own board to experiment with it...
Trying to get a shutdown button working, it seems like this code would work for my purposes?
I'm using GPIO 3
import RPi.GPIO as GPIO
import os, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(3,GPIO.IN, pull_up_down = GPIO.PUD_UP)
def shutoff(channel):
os.system("sudo shutdown -h now")
GPIO.add_event_detect(3,GPIO.FALLING, callback = shutoff,bouncetime = 2000)
The code I'm paraphrasing also has this at the end, is that needed?
while True:
time.sleep(1)
I notice that channel is a shutdown param but is never used
The while loop at the end is indeed needed, as otherwise the program would just finish and quit, rather than wait for the button press.
But if your code is doing other stuff instead, you can omit the while and rely on the existing loop.
Ahh ok so this should be incorporated into my main code?
Could it be while True: pass?
That would work, but it would use 100% CPU. The sleep calls let the CPU idle most of the time.
Ahhhh yes. I'm used to MCUs where time.sleep(number) doesn't allow you to do anything else
I'm trying to follow this tutorial, https://learn.adafruit.com/raspberry-pi-led-matrix-display/software which I followed with an installation a few years ago for my RPi 2, which works flawlessly. I'm trying to install now on a new RPi 3 without success because I get this error when I try to show images on the matrix (I've confirmed the matrix is working just fine otherwise. Here's the error: File "test.py", Line 1, in <module> import Image ImportError: No module named Image
so I looked to see where to get the module, and it says at effbot.org. It seems effbot.org is no longer in operation. So, after searching a bit I find that Pillow has taken over this function, so I install Pillow and it still doesn't work ("No module named Image"). So I try pip install image and I get this warning: The script django-admin is installed in '/home/pi/.local/bin' which is not on PATH. Consider adding this directory to PAT or, if you prefer to suppress this warning... Anyway, trying to run script still says "No module named Image".
With Pillow the Image module is a sub module so you probably want from PIL import Image
Thanks, I will try that in the morning and let you know. Very late here now I just realized!
Hello! I'm using a SSD1306 on raspberry pi with adafruit_ssd1306 . Digged into documentation but cant find how to flip output (rotate 180° horizontally). Did someone encountered my issue?
dsplay.rotate?
That worked! Thanks. Only problem now is the LED matrix is pulsing about 1x per second with a bright flash affecting a line and a few leds. My RPi 2 doesn't do that while running the same code. I will try different --led-slowdown-gpio values, but if anyone happens to know the best value to use for RPi 3B+ please let me know. Or maybe it's a different issue? Will update if I figure it out.
Is that possibly a power supply issue? Like maybe you're maxing out the power supply while driving the display and the Pi together? Do you have any way of monitoring current consumption?
Good idea but unlikely. The hat uses a different power supply than the Pi, and it's the same power supply I used without issue with the RPi 2 (and it's 2 amps, way above specs needed).
OK, I found that the --led-slowdown-gpio command is in the matrix.cfg file, but I tried every value and I'm still getting a pulse every second that flashes bright, like a refresh. Stuck for now.
I'll assume you've already looked at the system logs. I'd still suspect the power supply and pop a scope on the power rail to see if there was a big pulse every second, which might be coming from somewhere else. Mightily suspicious in any case...
Here is a blue screen test (sorry it's sideways). The unevenness is simply the refresh rate being different than the video capture, but the flashing every second seems to have something to do with this line in my code: time.sleep(80) The flash literally happens every second, and if I change that 80 to 15 it happens 15 times.
Thank you for your help. I have not looked at the system logs. What should I look for?
You'd be looking in either /var/log/messages or /var/log/syslog for anything that is happening around once a second, repeatedly. You can also open a terminal and just tail a log with: tail -f /var/log/messages while your program is running. If you don't see anything in the log while it's running, nothing is getting written to the log.
Does your program use asyncio or threads or multiprocessing?
Here's the program: #!/usr/bin/python
A more complex RGBMatrix example works with the Python Imaging Library,
demonstrating a few graphics primitives and image loading.
Note that PIL graphics do not have an immediate effect on the display --
image is drawn into a separate buffer, which is then copied to the matrix
using the SetImage() function (see examples below).
Requires rgbmatrix.so present in the same directory.
PIL Image module (create or load images) is explained here:
http://effbot.org/imagingbook/image.htm
# http://effbot.org/imagingbook/imagedraw.htm
from PIL import Image
from PIL import ImageDraw
import time
from rgbmatrix import Adafruit_RGBmatrix
# Rows and chain length are both required parameters:
matrix = Adafruit_RGBmatrix(16, 1)
matrix.Fill(0x6F85FF) # Fill screen to sky color
time.sleep(80)
matrix.Clear()```
What I'm suspecting is that somewhere in the code that you're using (the libraries you're importing) you've possibly got some code running that time.sleep() might be blocking. If there's a relationship between how much time you're sleeping and the pulses there's clearly some kind of interaction, which might be happening at a thread level, dunno enough about this. Just out of curiosity, if you broke that 80 seconds into 80 1 second sleeps in a loop, printing to the console between each time, you might get some notion of the correspondence.
Bit late here so I'm off to bed but good luck, it sounds a bit like you're on the trail of it. You can also locate the installed libraries on your Pi of Image and ImageDraw and shove temporarily print statements in there to see at what point things are happening. That is, if you're willing to dig into the middle of that code and find the problem yourself. Maybe somebody else around here has a better idea.
Nothing happening 1x per second in messages or syslog
One way to make sure it's not power supply related to the display is rather than displaying a sky blue color, just display a very very dim gray which will use up much less power. If that doesn't make any difference it's not likely power related.
Thanks so much for your help. Sleep well! 🙂
yeah, I didn't think it would show up in the logs but it might have indicated something else going on in the system. Good to narrow things down.
You're welcome, good luck!
Great avatar image btw.
For anyone else, is there an alternative way to hold an image on the screen without using time.sleep()?
Eventual goal is to have an image fade up, hold for a few seconds, and then fade out.
How can I set the demo/examples (clock) to the middle of the matrix panel. Every time I'm starting the clock demo it appears in the left upper corner.
Command: sudo ./clock -f /home/pi/rpi-rgb-led-matrix/fonts/10x20.bdf -C 255,0,0 --led-rows=32 --led-cols=64
how can I investigate rc.local to see if code is being run from there on startup? With Cater's help I tracked down how I think code on this system is being run from startup but the code sitting in the folder called Autostart on the desktop doesn't seem to match the system output
It looks like you can pass -x 10 and -y 20 command line options to set the offset coordinates of the text.
Can I use a RP2040 board running off of 3-5v to drive standard earbuds/headphones?
Having another problem. I'm trying to run some test code that uses RPi.GPIO. I'm getting a warning that 'This channel is already in use.' When I use GPIO.setup(GPIO.BCM)
I've done it on other microcontrollers that way, so presumably yes.
I've got a matrix led panel and the raspberry pi hat from adafruit. I used this (https://learn.adafruit.com/adafruit-rgb-matrix-plus-real-time-clock-hat-for-raspberry-pi/driving-matrices#step-2995409) and startet the pre installed clock demo with this command: ./clock -f /home/pi/rpi-rgb-led-matrix/fonts/10x20.bdf -C 255,0,0 --led-rows=32 --led-cols=64
My problem ist that the rgb's flicker escpecially then the time changes. Does anyone know why this happens and how i can change that.
The panel is not broken because I had it exchanged first.
Thanks in advance.
try adding some slow down
--led-slowdown-gpio=
For Raspberry Pi 3 use a slowdown of 1 to start (use higher values if image still flickers). For Raspberry Pi 4, use a slowdown of 4. Older Pi models might work with 0, try it.
Regarding the fIashing lines in my LED matrix with RPi 3B+... I ended up going back to my RPi2 running Python 2.7.13 and the old libraries where it works just fine. Interestingly, I just thought I'd try upgrading my RPi 2 to Python 3.6 so I could use Circuit Python libraries (part of this project is to use a capacitive touch sensor to trigger the LED matrix). I didn't even upgrade, all I did was this: sudo apt-get update sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
And the lines were running through the LED matrix again. No other changes, identical hardware (RPi 2, etc.).
the sudo apt-get update can be run without causing the problem by the way
So I guess now the problem is how do I use a capacitive touch sensor in Python 2.7.13? The tutorials on Adafruit only use the Circuit Python libraries which require Python 3.6
This really sounds like an issue for the product engineers then. Something in the Python support libraries, the OS support libraries to Python, etc. has changed something fundamental to the board.
If at all possible I'd get yourself off of Python 2 in any case.
Well, unfortunately, that's not an option. My deadline is in a few days. All I need to do is get this capacitive touch sensor to trigger an image on the LED matrix.
Understood.
This guide suggests putting all my code in a try-except block to catch keyboard interrupts. Is that valid?
http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi
Rather than valid, is that recommended?
Actually, what I'd do is just run an application loop that runs 24/7 and run the display off of its own thread, rather than the other way around. Two threads total.
You could also do that in asyncio but that's a lot to learn just for this.
Anything will do, just where do I find code that will work with the capacitive touch sensor without Circuit Python?
@ripe berry do you have a sensor in mind?
I have this one: https://www.adafruit.com/product/1374
The product guide for that tells how to use it as an input device: https://learn.adafruit.com/adafruit-capacitive-touch-sensor-breakouts/downloads
That's a link on the product page.
Yes, but the guide says you have to use Circuit Python which requires Python 3.6, which messes up my LED matrix, so I can't use Python 3.6 for this project.
No, the device has just a single output pin. So long as you're powering it with 3.3v you can take its output directly into a GPIO pin.
Why do you need CircuitPython for that?
OK, sorry, I'm such a noob. I need some code examples, and the only examples on the Adafruit web site dealing with this sensor say you have to use Circuit Python. Can you please point me to any example of Python code that "listens" to a GPIO pin to go high, and then proceeds with the rest of the program?
No, I'm going to at least make you do your own homework as it's trivial. There are several python libraries for reading and writing GPIO pins. Just search on GPIO Raspberry Pi Python. It's like Raspberry Pi 101, there'll be thousands of web pages.
...or "reading a GPIO Pin Raspberry Pi"
Great, that's very helpful! I didn't even know what terms to search for. 🤪
Thank you!
The Pi has a GPIO bus of 40 pins. and you want to read the digital value of an external device into one of them. https://pinout.xyz/#
The comprehensive add-on boards & GPIO Pinout guide for the Raspberry Pi
Use one of the green-colored pins.
Those are the standard GPIO pins that aren't used for anything else.
And the site is interactive, you can click on a pin and see what possible ways it can be programmed/used.
I'd probably recommend using RPi.GPIO as it's the easiest and most direct library for beginners.
Most of the main python libraries are documented at PyPI, with full API documentation. Here's the home page for RPi.GPIO: https://pypi.org/project/RPi.GPIO/
That should give you a major head start.
1000 thank yous! This is exactly what I was looking for! Sometimes things are so basic that it's difficult for advanced people to understand how a noob could not have the slightest idea what's going on. I generally just follow Adafruit tutorials, but the tutorial on this sensor says nothing about how to use it with RPi, and the only tutorials on using capacitive touch sensors on Adafruit say to use Circuit Python. I'll be doing lots of reading tonight, and hopefully all this will be up and running within the next few days. I'll post it here when I'm done. 🙂
What does the channel parameter do here? It doesn't seem to be used
and can I add the event listener to my main code? And just have shutdown handled from there?
what i would do is something like this:
try:
my_main_code()
except KeyboardInterrupt:
print("keyboard interrupt, exiting")
finally:
cleanup_stuff()
so that any except that isn't KeyboardInterrupt will be shown. even if something other than keyboard interrupt is thrown, finally: will still executed
(also finally will run even if try doesn't error)
would my_main_code() be defined in the same file? Also can I just include a def for shutdown function as well as add the event listener to my main setup?
Can sombody help me reading Serial output of 2 arduinos in Pyserial at the same time? i'm not very much familiar with pyserial but i've managed to read the data from arduino but i want to read and write on 2 Arduino at the same time
IF you can send me a simple Python example script that can read serial data from 2 USB ports of the Raspberry pi at the same time, that would be much appreciated
Please ping me when you reply
The simplest thing to do would be to read both ports in a loop, like:```python
port1 = serial.Serial('/dev/ttyUSB0', timeout=0)
port2 = serial.Serial('/dev/ttyUSB1', timeout=0)
while True:
data1 = port1.read()
if data1:
# Do something with the data
data2 = port2.read()
if data2:
# Do something with the data
time.sleep(0.01) # avoid 100% busy-waiting```
having a weird problem. 2 raspberry pi 3 A+s won't show up on my monitor
Using a 3A adapter so no worries there
the green ACT LED has not blinked so far
monitor is plugged in, let me try the other port on the monitor
Thanks, i have one question, if i use time.sleep(1) in the loop, and then i read the serial port, will it return me the data that was also sent while the script was sleeping or will it only return me the recently sent data at that instance of time?
The port will accumulate data it received between read() calls, as it's all buffered up by the OS.
that's not good, (might be useful in some applications but at least not in mine) i want to only fetch the latest sent data by the arduino after sleeping my script for 1 second
Make sure you don't have a power-only USB cable.
I'm connecting to the monitor with HDMI
You can do that too. The pyserial object has something like a flush_input() method to discard old data.
OK, SO i will call flush_input() before ser.read()?
I don't have any experience with tunneling USB over HDMI. Didn't know that was a thing, actually.
oh I think I used the wrong words
I'm trying to just get the main desktop to show up on a monitor with an HDMI cable plugged into the pis HDMI port
Oh, gotcha. My mistake, sorry.
not to worry 🙂
port2 = serial.Serial('/dev/ttyUSB1', timeout=0)
while True:
port1.flush_input()
data1 = port1.read()
if data1:
# Do something with the data
port2.flush_input()
data2 = port2.read()
if data2:
# Do something with the data
time.sleep(0.01) # avoid 100% busy-waiting```
Like this?
Sorry, the call is actually reset_input_buffer().
You'd want to perform the reset when you want to start listening to the Arduino again. If you do a reset and then immediately read() right afterwards, chances are there won't be any data in that fraction of a second.
OK, So for example, in this snippet of code
port2 = serial.Serial('/dev/ttyUSB1', timeout=0)
while True:
data1 = port1.read()
if data1:
# Do something with the data
data2 = port2.read()
if data2:
# Do something with the data
time.sleep(1) # avoid 100% busy-waiting
port1.reset_input_buffer()
port2.reset_input_buffer()
time.sleep(0.2)
I mean, that will work, but it will just randomly discard about 80% of the data that the Arduino sends.
well, my_main_code would be all the code you want to "catch" (usually it's a function but it doesn't have to be - you could put your entire program in there if you want to catch the whole program)
the function names can be replaced with the code you want to run
makes sense thanks. Any idea why 2 pis in a row, one fresh out of the box, would not display on a monitor?
i think you are missing the point here, the thing im trying to accomplish is that, Arduino is sending a string, for example, "Hello World" continuously after let's say 50 miliseconds, i want the python script's port1.read() function to only fetch and store the last string "Hello World" Sent by Arduino at that instance of time when the read() method is called
Do Pi's display anything if their boot image is bad?
ohhh
one of them doesn't have a card in it!
One does though, and doesn't display
hmmmm
Corrupted SD CARD maybe
how can I go about determining if the boot image is OK on a windows machine?
or bad OS IMAGE
In that case you might want to not use the timeout parameter and instead do like a read(12) call to force it to wait until it has the next message.
But in general you might run into trouble with getting partial messages too, like "orld. Hello w"
is there any reliable way of transmitting data wired from arduino to raspberry pi Python?
Generally the USB serial port is reliable, in that all the bytes you send are received. It's up to you to decide what to do with those bytes, though.
Maybe you want to actually send a command from the Pi to the Arduino, telling it when you want a response?
hmm, interesting
i wonder how that would work?
snippet of code?😅
i think i'll need to use .write() method and then arduino will check if serial.available(), parse the data and compare it
On the Pi side, you'd just do a write(b"stuff") to the serial port. The Arduino side would need some more modifications, since it would need to read from the serial port, etc.
you don't really, you would either try it and see if it boots, if it doesn't work then you would reflash the sd card
(the raspberry pi os imager is a great tool btw)
I have that tool! Is there anything else I can try before that drastic step?
Hmmm, I got it, Thank You so much for helping me out and suggesting me good solution
i would make sure:
- you actually have a flashed sd card plugged into the pi
- adequate power (at least 2 amps, 3 for pi 4)
- display cable is fine
- monitor is fine
2,3,4 are checked and this SD worked fine yesterday
Can I get any files off of the SD card?
Or are they lost?
does the sd card work in another pi?
Let me try
is your setup this?
2 pis of same model
both have flashed sd cards that used to work
one doesn't boot anymore
(just wanted to confirm)
actually I only have 1 flashchard that's been flashed
are the pis the same model?
yup
I have 2, but one is flashed
what's the other one doing?
a raspberry pi needs a flashed sd card to boot
yeah I'm only use the flashed one
and that flashed one only works in one out of two pis?
it works in neither
and it was working yesterday?
sorry if i'm being so annoying just trying to get all the facts straight
Not to worry, facts are important
normal if the pi was on for a long time
It was about 5 min
hmmm
ok now when I plug the SD card into my PC it cannot access it whereas previously I could see stuff on there
did anything happen between yesterday and today? (like did power go out, or you pulled plugged on pi power cable)
any error messages? or just nothing?
"this drive does not contain a recognized file format" or something like that
and "this drive is inaccessible"
that's normal cause windows doesn't know how to read the file system for linux
but do you see a boot drive
no
strange
it mounts as a USB drive
what is the drive called
"USB Drive (D:)"
can you see anything in that drive?
interestingly D: is the face I'm making rn
or it says inaccessible
ok um give me a min pls sorry
do you see something like the drive circled in blue and/or green?
those are the two new entries i get when i plug in a sd card that is used to boot a pi
and you don't see the boot drive anymore??? that probably means its corrupted - reflashing is the easiet route
(you could boot a linux computer, plug the drive in and recover files cause the drive that pops up has a filesystem that linux can read but you would have to do some magician work and idk how to do that 😦 )
Hahah ok I figured it was lost. At least I backed up
We had a power outage, I guess that killed it
makes sense
UPS system wouldn't be out of order I think
if a pi loses power unexpectedly without proper shutdown there is a chance to break the filesystem
how did you backup? disk image? (.iso) or copy a bunch of directories?
Oh only thing of value was a .py file
easy then
I actually didn't back it up I just shared it here lol. This is why I want our org to have a github account
haha
So I can make silly mistakes
not silly mistakes - learning 🙂
just reflash the sd card, have the pi boot into and plop the python file back to where it was originally
Now I have a weird problem
My 32GB SD card is reading as 0.0 GB
what did you do?
keep goign on with it
Ah sorry, the imager errors and tells me it's 0.0
can you share screenshot?
yeah one moment
first image:
I tried writing anyway and it wouldn't let me
oh wow
one sec
what was the error?
gotta unplug this, the SD card is burning hot
oh no
yeah I can't even touch it
that sd card might have gone bad
I guess this one is trash
I paid out of pocket for this and brought it to the job too
are you using usb to uSD card adapter?
and was it this hot when you plugged it into the pi?
pi and PC
then it's probably broke
if you have a magnifying glass, does the backside look weird?
(like any broken traces, burned parts maybe???)
one sec, uploading a photo
photo comes with a bonus view of my favorite green pants
uniqlo if you're interested in a pair yourself
haha
can you take the uSD card out of the sd --> uSD adapter and see anything?
maybe the adapter is faulty? try another one?
I don't have another adapter, but I can try another SD card
given that the SD card got hot in the Pi as well, I think it's a pi problem
oops
i think it's a sd card problem - try flashing another one?
an SD problem rather
yea lol
ok burning a new image
ack! I hit the format button
I'll have to bring this home with me
But I only have a raspberry pi 2.
Default is 1. Try 0. What kind of flicker is it? If there are flashes across the screen that happen every 1 second, then that is a bug I discovered with older hardware together with newer software (see above discussion). #help-with-linux-sbcs message
Can I add the event listener for my shutdown button pins to my main script? Or does shutdown need its own thing?
You should be able to add it to your main script, if it'll be continually running.
Does the event listener take advantage of threading?
I'm not entirely sure how the callbacks work in the Python threading model. The documentation says they rely on a darksidesync async function library.
hmm, I can't find the exact guide I was referencing
shoot
There seem to be a number of ways to do a shutdown button on a pi, does this seem like a decent method? https://www.makeuseof.com/tag/add-power-button-raspberry-pi/ I'm specifically looking for something that can be incorporated into my main script's While True: block
yes. looks fine.
the use of etc/rc.local is sort of out dated, but i think still works
I also need to figure out how to run on start up, is there a best practice there? I also see a number of ways to do that
^^ that's the generally recommended approach
guide was written when sysv was still transitioning to systemd, so covers both
but you could just try using /etc/rc.local as that power button guide shows and see if that works
i'm guessing it does...there's a systemd service setup by default to essentially do that to maintain backwards compatibility
you'll also find mention of @reboot in cron. i've never tried that approach though.
hmm would the systemd method not work with the Make Use Of method?
oh wait
nevermind, systemd is for on startup right?
yes. it's an entire init framework (as was/is sysv). it's a huge topic.
yeah seems like it
it's what brings up everything, like networking, etc.
so I would add the shutdown code to my main script and then have systemd run the main script on startup?
shutdown script contained within my main code right?
ahh
very simple script
would that be automagically running in another thread?
that being the shutdown script
#!/usr/bin/env python3
from gpiozero import Button
import os
Button(21).wait_for_press()
os.system("sudo poweroff")
that's the entire script
does wait_for_press wait for 21 to go low? that's how my button is wired, although not with 21
correct
perfection
if you change pins, change code
guessing that guide uses pin 21
but can be any available GPIO pin
nothing special about 21
that's what I figured
yep. guide just uses pin 21. probably because it's there on the end right next to a GND pin.
probably good to avoid using the I2C (2/3) and SPI (9/10/11) pins, just in case you want to use those for something else later
but if you wanted, those could be used
I'm currently using SCL, but I'm not doing any I2C for this project so it's fine
oh, pi also has pull ups on the SCL/SDA pins. but can still add button. just know they are there.
not really. just wire button between pin and GND. same as that guide shows.
in general, you'd want some kind of pull anyway, to avoid having a floating input
so I accidentally made a good choice heh
have you read up on using pulls up/down resistors with buttons, why they are needed, etc?
pi also has internal pull ups which can be enabled, helps to easily move to any other pin
ahh, I've already ordered the hat board that uses SCL so I'm locked in, but I can change it in the future
a little odd the code from that guide doesn't appear to enable anything. it may be buried in whatever that wait_for_press() code does
probably yeah. So to rehash, do I want both my main code and this shutdown code to be running from systemd?
what is your main code?
I can upload it
It plays a song and triggers relays at certain points in the song
and you've got that working and tested by running directly?
and now want it to auto run at boot?
yup!
then, yes, same general process
you can setup more than one "service" to autorun
so they don't need to be dealt with together
and in general, all those same other options are available, /etc/rc.local etc.
ahhh
you just need to follow whatever process twice
and the OS will handle threading? Is threading the right term?
yes
that's pretty neat
that's the benefit of using a micro that's running a full linux operating system
but also the downside...since it comes at the cost of complexity
a tradeoff is you can't do super precise timing right?
correct
neopixel usage is a good example for that
trivial on an UNO
painful but doable on a pi
makes sense, thnks
do raspi auto updates on first start usually take north of an hour? Or is my wifi just bad?
Could be either, really.
You shouldn't need to use sudo for installing most things.
@lost wolf you thinking pip installs? for distribution packages, like git, you would typically use sudo with apt to install
Oh, yes I was. You are correct.
@civic rune ^^
Ooh thanks!
Can't seem to re-find the python (not CP) version of this library/how to install. Am I looking in the right place?
@civic rune Guide doesn't cover it. Are you looking to use it with Blinka? If so, check the README for PyPI install instructions. https://github.com/adafruit/Adafruit_CircuitPython_74HC595
ahhhhh
thank you
how do I upgrade my pi to python 3?
to use pip3
oh Blinka has to be installed to right?
ahh it installs for you
I tried 0. The hard flicker then the time changes is gone but there is still a permanently flicker. Do you think it would work if I will buy a raspi 4. I have to be sure cause I don't wanna waste 60€ for a pi4 XD
What does this code do?
chmod a+x autoshutdown.py
and do I need to be in the folder that autoshutdown.py is in?
ah it's changing file permissions, interesting, what does that do?
chmod a+x will modify the permissions on autoshutdown.py file so it is allowed to be executed
Ahh ok
this lets the computer see it and know it's ok to go ahead and run it
if I want to have two scripts, one for Autoshutdown and one for my main script, do I need to chmod a+x my_main_script.py?
based on how you're calling that file, yes the my_main_script.py will also need permissions to execute
ok cool, I want the main script to run on startup, I have gotten advice to use systemd for that, does that conflict with this method?
I don't believe so, it should be fine
ok thanks. There are so many ways to do things on the pi, I get overwhelmed
yup! It can be a lot, but it also means you've got options if you hit a wall, and that it'll probably be possible to do
This is for the beaglebone, do I still need to be in root?
yes
hmm cd root didn't work. How do you cd up one level? I was at
pi@raspberrypi: ~$
and I accidentally did cd / and now I'm in pi@raspberrypi:/$
ahhh I was adding a /
cd / go to root folder
is that root or just the root of the path I'm in?
root path, not root the user
ok
how do I get to root like in the guide?
cd /root
or just invoke sudo on the text editor and use absolute path
sudo nano /root/mouse.py
ahhh that opens a new file right?
yes
so sudo thonny /root/autoshutdown.py?
should I put my main script in /root/ as well?