#help-with-linux-sbcs

1 messages · Page 18 of 1

civic rune
#

I need to run a simple LED button switch's LED from a GPIO, I see that the max current is 16 mA, is 10 mA a safe number to use as my drive current when selecting a current limiting resistor?

umbral sable
civic rune
#

Oooh, is that info available in pinout.xyz?

umbral sable
#

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.

civic rune
#

Ok, would the official raspi site be a better place to look?

umbral sable
#

Not sure off the top of my head, so I'd just be going to look there too to see. 😉

civic rune
#

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

civic rune
umbral sable
#

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".

civic rune
#

ahh ok

#

I don't see any callouts for other pin current limits, I think I'm safe with 10 mA

umbral sable
#

Yep, should be fine.

fleet spire
#

It might be: what is the 4th wire, the data's ground, supposed to connect to?

merry merlin
#

So I hope to learn alot from guys like you too

gentle briar
fleet spire
agile depot
#

Can Lidar detect speed accurately if it is stationary?

#

I’m looking to use it with a raspberry pi to track car speeds

umbral sable
agile depot
#

Which would be more accurate?

umbral sable
#

Not sure, it would depend on the performance specs of the unit... there's a wide range of lidars out there.

agile depot
#

Would Lidar Lite v3 or v4 work?

umbral sable
# agile depot 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.

hardy plaza
#

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.

agile depot
#

You mean a field doppler radar thing? I was kinda drawn away from those because of the low lifetime on some of them

hardy plaza
#

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

sterile barn
#

Is there something like a fan stand for raspberry pi thonk

#

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

hardy plaza
#

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.

sterile barn
#

That's a very conveniently-shaped piece of aluminum thinkies

hardy plaza
#

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.

agile depot
#

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.

hardy plaza
agile depot
#

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

umbral sable
#

Note that they say the range is only like 10m on that radar chip, I think.

agile depot
#

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

hardy plaza
#

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.

hardy plaza
#

Just by comparison, some police lasers operate at 600m-1km, with X-band radar guns operating at up to several miles away.

agile depot
merry merlin
#

What is the closest thing to a LiDar or iTOF that I can get for a raspberry pi on this site is?

merry merlin
umbral sable
steady rose
turbid rivet
turbid rivet
ripe berry
#

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.

steady rose
#

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

ripe berry
#

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.

lost wolf
#

Always back up first 😄

merry merlin
merry merlin
#

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

umbral sable
turbid rivet
#

Oh, that is an application that requires some degree of real-time depth mapping...

turbid rivet
hardy plaza
# agile depot Would this work at a high enough speed? I don’t know the refresh rate of it. htt...

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.

agile depot
#

Ok, I don’t know what Doppler radar I should use then, the DigiKey A111 is discontinued.

turbid rivet
# merry merlin The end goal is to create a product that creates and saves an entire environment...

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

agile depot
turbid rivet
merry merlin
merry merlin
turbid rivet
# agile depot The device will be fairly close to the road by the way, the person I’m working w...

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.

hardy plaza
# turbid rivet If you're looking to measure the velocity of cars on a road, and you can mount s...

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.

merry merlin
agile depot
#

It also cant touch the road

agile depot
civic rune
#

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?

steady rose
#

unless you set something up, none are

civic rune
steady rose
#

then it'd be whatever they setup. got any more info?

civic rune
#

Not a ton, I was hoping there was an easy way to determine this. What info would I need?

steady rose
#

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?

civic rune
#

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

coarse imp
#

can I ask "idea" question here?

civic rune
#

You can ask any question that is relevant and G rated!

coarse imp
#

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?

steady rose
#

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

umbral sable
#

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.

civic rune
#

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.

umbral sable
#

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.

coarse imp
#

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.

civic rune
steady rose
#

dmesg | grep changed_filename.py for a quick/easy look

#

does the project have any kind of install and setup instructions?

civic rune
#

Ha, not really. Not for the software

civic rune
steady rose
#

worth a try at least

civic rune
#

ok! I will try that

steady rose
#

how did you get the .py files onto the pi?

civic rune
#

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

steady rose
#

are you on one of those pi's right now?

civic rune
#

I can be, it's a short distance from my office

#

ok, at the pi

steady rose
#

wow. that was short.

#

any special user account being used? or just default pi?

civic rune
#

there's the warning regarding default pi user

#

and SSH

steady rose
#

those warning are being shown?

civic rune
#

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

steady rose
#

ok, so you're logged in as regular pi user?

civic rune
#

seem to be

steady rose
#

where are the .py files located?

civic rune
#

on the desktop

steady rose
#

know how to open a terminal window?

civic rune
#

there's a button for that right?

#

looks like a terminal?

steady rose
#

maybe? try it. i've never used pi in gui mode.

#

you should get something that looks like when you ssh in

civic rune
#

i have a window with pi@raspberrypi:~ $

steady rose
#

cd Desktop

civic rune
#

done

steady rose
#

how many .py files are there?

civic rune
#

4

steady rose
#

ls -l *.py

#

what owner/group do they show?

civic rune
#

pi pi

steady rose
#

these have been currently setup to auto run? so they are running now?

civic rune
#

I assume

#

I've been dealing with printer problems all morning and haven't looked at the codeyet

steady rose
#

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

civic rune
#

for my edification, what are these commands doing?

steady rose
#

listing all running processes (ps) and then only showing ones that have matching text (grep)

civic rune
#

ahh

civic rune
steady rose
#

no/yes

#

doesn't matter

#

but trickier to enter

#

just use text up to a space

civic rune
#

the file is 0 everydoor opens until end.py

steady rose
#

use everydoor

civic rune
#

ooh ok

steady rose
#

ps -ef | grep everydoor

civic rune
#

ah right GREP is regular expressions right?

steady rose
#

it uses those for the pattern matching

civic rune
steady rose
#

ok, not running

#

the one return is just the grep command itself

civic rune
#

Ok I'll try the other 3 and get a pic

steady rose
#

go through same check with other files

civic rune
#

For the file 1 short music light show.py

#

and for the other 2 files, these look like they are not running

steady rose
#

yah, doesn't look like anything is running

civic rune
#

So none of these files are being used?

steady rose
#

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?

civic rune
#

It is

#

Or seems to be

steady rose
#

can you describe?

civic rune
#

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

steady rose
#

is there any user interaction involved?

civic rune
#

nope

#

it's just a christmassy display

steady rose
#

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

civic rune
#

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

steady rose
#

do you see forever loops in the files?

civic rune
#

I'm picking up lunch ATM, on my phone but I'll check when I get back

steady rose
#

ok. check that next and report back.

#

that info will give some clue as to how these were meant to be used

civic rune
#

Will do, appreciate the assistance

civic rune
#

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

?

steady rose
#

rpi.gpio may come preinstalled these days? not sure.

#

but in general, it's just another python package.

#

blinka uses it under the hood

civic rune
#

ahh ok

steady rose
#

are there any import board lines?

civic rune
#

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

steady rose
#

then probably not using blinka

civic rune
#

it's using RPi.GPIO, time, and pygame

steady rose
#

that's fine

civic rune
#

I think only one of these files is supposed to run at any time, I think they give you options for functionality

steady rose
#

there's nothing but digital IO going on (pre the schematic)

#

so using rpi.gpio is fine

civic rune
#

is board better if you're doing SPI or I2C/S ?

steady rose
#

sort of. it's really more if you want to use circuitpython libraries.

civic rune
#

makes sense, I thought they were using shift registers but I see no evidence in the code

steady rose
#

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

civic rune
#

makes sense

#

I'm using blinka for the refurb on the other project a diff team did

steady rose
#

if you're just setting digital pins high/low

#

can stick with just using rpi.gpio for now

#

are you still at the pi?

civic rune
#

can be!

#

need to put down my burrito but that's easy

steady rose
#

crontab -e

lost wolf
#

burritotab -e more like.

steady rose
#

run that and see if there are any entries

civic rune
#

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?

steady rose
#

in terminal, same as running the ps commands

civic rune
#

what's the same?

steady rose
#

same as how you ran the ps commands

#

in a terminal window, which will be "on the desktop" i guess

civic rune
#

ohhhh I misunderstood

#

One sec, uploading the pic

steady rose
#

select 1

#

press enter

civic rune
#

ok I see a bunch of blue text about chron

#

cron

steady rose
#

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

civic rune
steady rose
#

ok. nothing there.

civic rune
#

So they aren't using cron?

steady rose
#

doesn't look like

civic rune
#

Hmm

steady rose
#

at least not as pi user

civic rune
#

I doubt they set up another user

#

But is there a way to tell?

steady rose
#

does the calendar do stuff? like whatever is plugged into all those relay controlled outlets?

civic rune
#

Yup

steady rose
#

how often does it change?

#

daily? hourly?

civic rune
#

It runs through a 5-10 min program playing music and switching relays

steady rose
#

how often?

civic rune
#

Over and over as far as I can tell

#

Seems to restart when it finishes.

steady rose
#

have you rebooted the pi at some point ever?

civic rune
#

Yes

steady rose
#

and it when it comes back up, it starts running the calendar?

civic rune
#

Seems to yes

steady rose
#

the calendar is currently doing stuff?

civic rune
#

It's currently informing me of a Holly jolly christmas

steady rose
#

yah, try ps -ef | grep py

#

seems like something is currently running

civic rune
#

how do I get out of the crontab stuff

#

ah CTRLX

steady rose
#

<CTRL><X>

civic rune
steady rose
#

cd Autostart

#

ls

civic rune
#

'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

steady rose
#

how big is that .py file? like how many lines of code?

civic rune
#

trying to find it

steady rose
#

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

civic rune
#

through a marginally awkward process, I can

#

give me 15 minutes or so

#

I have to find a drill to open this enclosure

steady rose
#

wait. not yet.

#

can just open it there and look real quick

#

more 4\ low\ current.py

#

run that and take photo

civic rune
#

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

steady rose
#

is the pi connected to internet? could curl it up to a pastebin.

civic rune
#

I have wifi on my laptop but not on my phone, I think the pis wifi chip doesn't have have oomph

steady rose
#

ok, nvm. it'd be the pi that would need to be internet connected.

civic rune
#

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

steady rose
#

it looks like it will loop 400 times and then exit

civic rune
#

interesting

steady rose
#

but that's probably what is currently setup to "auto run"

#

it's using a feature of the desktop ui

civic rune
#

interesting

#

Is it a good way to autorun?

steady rose
#

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

civic rune
#

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?

civic rune
steady rose
#

try this, if possible, move the file out of the Autostart folder and then reboot.

#

see if it then does nothing

civic rune
#

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?

steady rose
#

soft reboot fine

#

could probably also just log out of desktop / back in

#

but best to just reboot to be sure

civic rune
#

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?

steady rose
#

pi thing. it's just hiccuping when it comes back up.

civic rune
#

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

steady rose
#

yah. probably not.

civic rune
#

no idea why the relays were clicking on and off, that's unusual

steady rose
#

what action you are seeing is just from pins state changing by booting

civic rune
#

ahhh

steady rose
#

once up, it should be stable though

civic rune
#

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?

steady rose
#

they just wrote that 4 low current.py file and plopped it in that directory

civic rune
#

is that a default raspberry pi thing? A folder on the desktop named Autostart will run whatever is in it??

steady rose
#

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

civic rune
#

I do too! Really appreciate your assistance

steady rose
#

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

civic rune
#

I personally think it should be more elegant, but I don't have time before the deadline to mess with it

steady rose
#

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

civic rune
#

ooh good idea

#

is a while True: a better methodology?

steady rose
#

while (count < 1):

#

use True if you want forever vs. 400 times

civic rune
#

I can't see why we would want it to shut down after 400 runs but what do I know

steady rose
#

maybe it was a soft "forever"

#

sort of a failsafe if it was left unattended

civic rune
#

that makes sense

steady rose
#

ok. good luck. i think you've got a better idea of the setup now.

civic rune
#

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?

steady rose
#

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

civic rune
#

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?

civic rune
#

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

gentle briar
#

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.

civic rune
#

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?

tired marsh
#

yep

civic rune
#

huh

#

Their picture shows jumpers like this

tired marsh
#

that looks like GPIO3 and gnd

civic rune
#

and says to connect GPIO 5 and 6 to the button, but on pinout.xyz 5 and 6 are not there

tired marsh
#

no but it is physical pins 5 and 6

civic rune
#

ahhh

tired marsh
#

so that might be what they mean

civic rune
#

I should let them know that that's confusing

steady rose
#

there's wiringpi numbering also. each pin has (at least) 3 different designations. 🙂

#

does that guide say the button can power up also?

civic rune
#

It seems to yes

steady rose
#

can you link to guide. curious how they are doing that.

civic rune
#

One sec, at a staff meeting :)

steady rose
#

sure. np. whenever is fine.

civic rune
steady rose
#

thanks. yah, it's power down only really.

civic rune
#

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

lost wolf
lost wolf
#

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)."

raw solar
#

Might be able to bodge on a 3A Type C connector if the other components are up to the task

lost wolf
#

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.

raw solar
#

I think there are some breakouts that would make it easier, but certainly not something you can just plop on that board

steady rose
#

@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.

#

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

turbid rivet
#

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.

steady rose
raw solar
# steady rose 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

steady rose
#

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

raw solar
#

Yeah. Complicated, but doable

turbid rivet
raw solar
#

Don't want melties

civic rune
#

I love all this conversation about my problem, thanks folks!

civic rune
#

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?

civic rune
#

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

lost wolf
#

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!

turbid rivet
#

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.

lost wolf
#

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 🙂

turbid rivet
#

You can. For a headless server, display and peripherals would only be for accelerating the initial setup.

lost wolf
#

Yes.

#

Anything that an HDMI cable can connect to will work.

turbid rivet
#

Or VNC

lost wolf
#

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.

civic rune
#

A USB expander dongle isn't a bad idea either

#

2 ports seems like a lot, but it's not

turbid rivet
#

For a server, you’re usually not using a ton of usb devices.

civic rune
#

No but say you wanted to use a mouse, keyboard AND a USB stick for something, you'd be outta luck without a dongle

turbid rivet
#

A fan and heat sink are highly recommended for long term use

civic rune
#

I think 8GB is the min

lost wolf
#

Yeah smaller ones get more expensive as bigger ones get cheaper. 🤷🏻‍♀️

civic rune
#

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?

turbid ivy
civic rune
#

yes!

#

I struggle with english, my only human language

turbid ivy
#

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

civic rune
#

Ooooh

#

Multithreading!

turbid ivy
#

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

civic rune
#

Interesting, what "messy bits" does it handle?

#

I'm not opposed to a little light multithreading, I've always wanted to get into it

turbid ivy
#

the multiprocessing/multithreading. I try to avoid threading when I can personally

civic rune
#

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?

turbid ivy
#

Kind of like opening two terminals and in one terminal running main.py, and in the other running the shutdown script

#

ISR?

civic rune
#

Interrupt Service Routine

turbid ivy
#

ahh. I'm sure you could, but you don't need to get that into it. How are you starting the scripts on startup?

civic rune
#

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

turbid ivy
#

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

civic rune
#

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?

turbid ivy
#

yup! That'll do.

civic rune
#

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

turbid ivy
#

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

civic rune
#

I'm using Blinka and an adafruit library, would I need to figure out where those are stored?

turbid ivy
#

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

civic rune
#

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

turbid ivy
#

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

civic rune
#

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

civic rune
turbid ivy
#

If that's the case, I believe python should be able to have the path without issue

civic rune
#

ok I can test that soon with a simple blinky program

turbid ivy
#

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

civic rune
#

oooh

#

I just love python so much

#

I love my mom a LOT, but python is edging uncomfortably close

turbid ivy
#

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.

civic rune
#

I love the development speed

turbid ivy
#

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

civic rune
#

I LOVE circuitpython

#

I have to leave it behind next year for a project that's ill suited to python and I'm devastated

gentle briar
civic rune
#

Makes sense

#

thanks

turbid ivy
#

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 &

civic rune
#

OOOH

#

that's neat

turbid ivy
#

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

civic rune
#

I support this methodology, it makes the most sense to me

turbid ivy
civic rune
#

I see in your examples you don't run sudo twice?

turbid ivy
#

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 🙂

civic rune
#

makes sense!

turbid ivy
#

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

civic rune
#

I'm planning on testing it the way I would a CP project, so hopefully iron out the bugs

copper kelp
#

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

rocky flare
#

What does the soc look like without the ram?

copper kelp
#

bare chip in the centre, solder pads around it to fit the ram

faint sparrow
#

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?

GitHub

DIY Hydroponics Management System. Contribute to karikuiv/Hydroponics-system development by creating an account on GitHub.

gentle briar
#

It looks like nice neat code, but I'd wish for more comments.

faint sparrow
#

Thanks. Do you mean like explaining a little better what's being done per function or per component/file?

gentle briar
#

Yes, I also like to have comments explaining what each variable is for

civic rune
#

Does Doxygen do C code?

faint sparrow
#

Thanks and I'll also look into doxygen

civic rune
#

I've only used it for micropython, but I think it works for at least C++

#

Not sure about straight C

umbral sable
#

Yeah, it works for C too, since the syntax is basically a subset of C++.

civic rune
#

ahh cool, I suspected but didn't want to give bad info on the internet, we know how rare bad advice online is 😛

civic rune
#

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

civic rune
#

Here's what my header looks like

shell sentinel
#

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

umbral sable
shell sentinel
#

I believe so yes

umbral sable
#

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.

shell sentinel
#

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

umbral sable
#

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.

shell sentinel
#

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

umbral sable
#

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.

shell sentinel
#

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

umbral sable
#

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.

civic rune
#

What sensors are you using?

shell sentinel
#

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...

slate estuary
#

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.

umbral sable
slate estuary
#

Np, was actually cleaning some stuff up in it and I'll share ty

slate estuary
agile depot
#

Could I get a 128x64 monochrome OLED display to work on the QT PY 2040? I just need to draw shapes to it.

turbid rivet
#

Yes.

agile depot
#

Alright thanks

late peak
late peak
steady rose
#

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)
#

but also...not seeing what is the suggested replacement for the disco'd PID 1571 breakout.

late peak
turbid rivet
turbid rivet
#

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!

late peak
turbid rivet
#

Not to my knowledge.

steady rose
#

^^ all good info

#

thanks Hem

turbid rivet
#

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...

civic rune
#

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

umbral sable
#

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.

civic rune
#

Ahh ok so this should be incorporated into my main code?

#

Could it be while True: pass?

umbral sable
civic rune
#

Ahhhh yes. I'm used to MCUs where time.sleep(number) doesn't allow you to do anything else

ripe berry
#

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".

Adafruit Learning System

Show the Pi's video output on a large RGB LED matrix display!

fresh patrol
ripe berry
#

Thanks, I will try that in the morning and let you know. Very late here now I just realized!

fierce furnace
#

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?

ripe berry
hardy plaza
ripe berry
#

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.

hardy plaza
#

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...

ripe berry
#

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.

ripe berry
hardy plaza
#

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?

ripe berry
#

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()```
hardy plaza
#

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.

ripe berry
#

Nothing happening 1x per second in messages or syslog

hardy plaza
#

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.

ripe berry
#

Thanks so much for your help. Sleep well! 🙂

hardy plaza
#

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.

ripe berry
#

For anyone else, is there an alternative way to hold an image on the screen without using time.sleep()?

ripe berry
#

Eventual goal is to have an image fade up, hold for a few seconds, and then fade out.

lethal flame
#

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

civic rune
#

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

umbral sable
agile depot
#

Can I use a RP2040 board running off of 3-5v to drive standard earbuds/headphones?

civic rune
#

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)

lost wolf
lethal flame
#

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.

Adafruit Learning System

DIY your very own Times Square sign

steady rose
#

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.
ripe berry
# hardy plaza One way to make sure it's not power supply related to the display is rather than...

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

hardy plaza
#

If at all possible I'd get yourself off of Python 2 in any case.

ripe berry
#

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.

hardy plaza
#

Understood.

civic rune
#

Rather than valid, is that recommended?

hardy plaza
#

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.

ripe berry
#

Anything will do, just where do I find code that will work with the capacitive touch sensor without Circuit Python?

hard pike
#

@ripe berry do you have a sensor in mind?

ripe berry
hardy plaza
#

That's a link on the product page.

ripe berry
#

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.

hardy plaza
#

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?

ripe berry
#

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?

hardy plaza
#

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"

ripe berry
#

Great, that's very helpful! I didn't even know what terms to search for. 🤪

#

Thank you!

hardy plaza
#

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.

ripe berry
# hardy plaza Most of the main python libraries are documented at PyPI, with full API document...

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. 🙂

civic rune
#

and can I add the event listener to my main code? And just have shutdown handled from there?

opaque wagon
#

(also finally will run even if try doesn't error)

civic rune
#

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?

faint sparrow
#

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

umbral sable
civic rune
#

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

faint sparrow
umbral sable
faint sparrow
#

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

umbral sable
civic rune
#

I'm connecting to the monitor with HDMI

umbral sable
faint sparrow
#

OK, SO i will call flush_input() before ser.read()?

umbral sable
civic rune
#

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

umbral sable
civic rune
#

not to worry 🙂

faint sparrow
#
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?

umbral sable
#

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.

faint sparrow
#

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)
umbral sable
opaque wagon
civic rune
faint sparrow
umbral sable
civic rune
#

ohhh

#

one of them doesn't have a card in it!

#

One does though, and doesn't display

#

hmmmm

faint sparrow
civic rune
#

how can I go about determining if the boot image is OK on a windows machine?

faint sparrow
#

or bad OS IMAGE

umbral sable
#

But in general you might run into trouble with getting partial messages too, like "orld. Hello w"

faint sparrow
#

is there any reliable way of transmitting data wired from arduino to raspberry pi Python?

umbral sable
#

Maybe you want to actually send a command from the Pi to the Arduino, telling it when you want a response?

faint sparrow
#

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

umbral sable
#

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.

opaque wagon
#

(the raspberry pi os imager is a great tool btw)

civic rune
faint sparrow
opaque wagon
civic rune
#

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?

opaque wagon
#

does the sd card work in another pi?

civic rune
#

Let me try

opaque wagon
#

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)

civic rune
#

actually I only have 1 flashchard that's been flashed

opaque wagon
#

are the pis the same model?

civic rune
#

yup

opaque wagon
#

wait you only have 1 uSD card??

#

for 2 pis??

civic rune
#

I have 2, but one is flashed

opaque wagon
#

what's the other one doing?

civic rune
#

I have the 2nd one out to sanity check things

#

It's a spare/for a future project

opaque wagon
#

a raspberry pi needs a flashed sd card to boot

civic rune
#

yeah I'm only use the flashed one

opaque wagon
#

and that flashed one only works in one out of two pis?

civic rune
#

it works in neither

opaque wagon
#

and it was working yesterday?

civic rune
#

also the SD card slot was hot when I unplugged the device and pulled the card

#

yes

opaque wagon
#

sorry if i'm being so annoying just trying to get all the facts straight

civic rune
#

Not to worry, facts are important

opaque wagon
civic rune
#

It was about 5 min

opaque wagon
#

hmmm

civic rune
#

ok now when I plug the SD card into my PC it cannot access it whereas previously I could see stuff on there

opaque wagon
#

did anything happen between yesterday and today? (like did power go out, or you pulled plugged on pi power cable)

opaque wagon
civic rune
#

"this drive does not contain a recognized file format" or something like that

#

and "this drive is inaccessible"

opaque wagon
#

that's normal cause windows doesn't know how to read the file system for linux

#

but do you see a boot drive

civic rune
#

no

opaque wagon
#

strange

civic rune
#

it mounts as a USB drive

opaque wagon
#

what is the drive called

civic rune
#

"USB Drive (D:)"

opaque wagon
#

can you see anything in that drive?

civic rune
#

interestingly D: is the face I'm making rn

opaque wagon
#

or it says inaccessible

civic rune
#

no I cannot

#

inaccessible

opaque wagon
#

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

civic rune
#

Yeah I used to have a boot drive as wrll

#

Well

opaque wagon
#

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 😦 )

civic rune
#

Hahah ok I figured it was lost. At least I backed up

opaque wagon
#

good!

#

backups are very good

civic rune
#

We had a power outage, I guess that killed it

opaque wagon
#

makes sense

civic rune
#

UPS system wouldn't be out of order I think

opaque wagon
#

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?

civic rune
#

Oh only thing of value was a .py file

opaque wagon
#

easy then

civic rune
#

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

opaque wagon
#

haha

civic rune
#

So I can make silly mistakes

opaque wagon
#

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

civic rune
#

My 32GB SD card is reading as 0.0 GB

opaque wagon
#

what did you do?

civic rune
#

nothing haha!

#

I just went to flash it with raspbian and it says it it 0.0 GB

opaque wagon
#

keep goign on with it

civic rune
#

Ah sorry, the imager errors and tells me it's 0.0

opaque wagon
#

can you share screenshot?

civic rune
#

yeah one moment

#

first image:

#

I tried writing anyway and it wouldn't let me

#

oh wow

#

one sec

opaque wagon
#

what was the error?

civic rune
#

gotta unplug this, the SD card is burning hot

opaque wagon
#

oh no

civic rune
#

yeah I can't even touch it

opaque wagon
#

that sd card might have gone bad

civic rune
#

I guess this one is trash

opaque wagon
#

yea

#

wait

civic rune
#

I paid out of pocket for this and brought it to the job too

opaque wagon
#

are you using usb to uSD card adapter?

civic rune
#

yes

#

no

opaque wagon
#

and was it this hot when you plugged it into the pi?

civic rune
#

pi and PC

opaque wagon
#

then it's probably broke
if you have a magnifying glass, does the backside look weird?

#

(like any broken traces, burned parts maybe???)

civic rune
#

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

opaque wagon
#

haha

#

can you take the uSD card out of the sd --> uSD adapter and see anything?

#

maybe the adapter is faulty? try another one?

civic rune
#

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

opaque wagon
#

i think it's a sd card problem - try flashing another one?

civic rune
#

an SD problem rather

opaque wagon
#

yea lol

civic rune
#

ok burning a new image

#

ack! I hit the format button

#

I'll have to bring this home with me

lethal flame
ripe berry
civic rune
#

Can I add the event listener for my shutdown button pins to my main script? Or does shutdown need its own thing?

umbral sable
civic rune
umbral sable
civic rune
#

hmm, I can't find the exact guide I was referencing

#

shoot

steady rose
#

yes. looks fine.

#

the use of etc/rc.local is sort of out dated, but i think still works

civic rune
#

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

steady rose
#

^^ 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.

civic rune
#

hmm would the systemd method not work with the Make Use Of method?

#

oh wait

#

nevermind, systemd is for on startup right?

steady rose
#

yes. it's an entire init framework (as was/is sysv). it's a huge topic.

civic rune
#

yeah seems like it

steady rose
#

it's what brings up everything, like networking, etc.

civic rune
#

so I would add the shutdown code to my main script and then have systemd run the main script on startup?

steady rose
#

yep

#

basically replace the mouse example from that guide with the shutdown script

civic rune
#

shutdown script contained within my main code right?

steady rose
#

not sure. probably not.

#

it should be stand alone.

civic rune
#

ahh

steady rose
#

very simple script

civic rune
#

would that be automagically running in another thread?

#

that being the shutdown script

steady rose
#
#!/usr/bin/env python3
from gpiozero import Button
import os
Button(21).wait_for_press()
os.system("sudo poweroff")
#

that's the entire script

civic rune
#

does wait_for_press wait for 21 to go low? that's how my button is wired, although not with 21

steady rose
#

correct

civic rune
#

perfection

steady rose
#

if you change pins, change code

#

guessing that guide uses pin 21

#

but can be any available GPIO pin

#

nothing special about 21

civic rune
#

that's what I figured

steady rose
#

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

civic rune
#

I'm currently using SCL, but I'm not doing any I2C for this project so it's fine

steady rose
#

oh, pi also has pull ups on the SCL/SDA pins. but can still add button. just know they are there.

civic rune
#

oh

#

do I need to do any special code setup?

steady rose
#

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

civic rune
#

so I accidentally made a good choice heh

steady rose
#

have you read up on using pulls up/down resistors with buttons, why they are needed, etc?

civic rune
#

yeah I have

#

just wasn't thinking

steady rose
#

pi also has internal pull ups which can be enabled, helps to easily move to any other pin

civic rune
#

ahh, I've already ordered the hat board that uses SCL so I'm locked in, but I can change it in the future

steady rose
#

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

civic rune
#

probably yeah. So to rehash, do I want both my main code and this shutdown code to be running from systemd?

steady rose
#

what is your main code?

civic rune
#

I can upload it

steady rose
#

that's ok, just in general

#

what does it do?

civic rune
#

It plays a song and triggers relays at certain points in the song

steady rose
#

and you've got that working and tested by running directly?

#

and now want it to auto run at boot?

civic rune
#

yup!

steady rose
#

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.

civic rune
#

ahhh

steady rose
#

you just need to follow whatever process twice

civic rune
#

and the OS will handle threading? Is threading the right term?

steady rose
#

yes

civic rune
#

that's pretty neat

steady rose
#

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

civic rune
#

a tradeoff is you can't do super precise timing right?

steady rose
#

correct

#

neopixel usage is a good example for that

#

trivial on an UNO

#

painful but doable on a pi

civic rune
#

makes sense, thnks

civic rune
#

do raspi auto updates on first start usually take north of an hour? Or is my wifi just bad?

lost wolf
#

Could be either, really.

civic rune
#

oh fun

#

So when is it wrong to use sudo? I'm trying to install Git on my pi

lost wolf
#

You shouldn't need to use sudo for installing most things.

civic rune
#

hmmm

#

oh it looks like it's already installed with Raspbian

steady rose
#

@lost wolf you thinking pip installs? for distribution packages, like git, you would typically use sudo with apt to install

civic rune
#

Ooh thanks!

civic rune
#

Can't seem to re-find the python (not CP) version of this library/how to install. Am I looking in the right place?

lost wolf
civic rune
#

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

lethal flame
civic rune
#

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?

turbid ivy
civic rune
#

Ahh ok

turbid ivy
#

this lets the computer see it and know it's ok to go ahead and run it

civic rune
#

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?

turbid ivy
#

based on how you're calling that file, yes the my_main_script.py will also need permissions to execute

civic rune
#

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?

turbid ivy
#

I don't believe so, it should be fine

civic rune
#

ok thanks. There are so many ways to do things on the pi, I get overwhelmed

turbid ivy
#

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

civic rune
steady rose
#

yes

civic rune
#

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:/$

steady rose
#

cd .. go up one level

#

cd ~ get back to home dir

civic rune
#

ahhh I was adding a /

steady rose
#

cd / go to root folder

civic rune
#

is that root or just the root of the path I'm in?

steady rose
#

root path, not root the user

civic rune
#

ok

#

how do I get to root like in the guide?

steady rose
#

cd /root

civic rune
#

lol

#

duh

#

sudo cd root? permission was denied

steady rose
#

or just invoke sudo on the text editor and use absolute path

#
sudo nano /root/mouse.py
civic rune
#

ahhh that opens a new file right?

steady rose
#

yes

civic rune
#

so sudo thonny /root/autoshutdown.py?

steady rose
#

yes

#

if thonny is a text editor

civic rune
#

it is

#

comes with the pi

civic rune
#

should I put my main script in /root/ as well?

steady rose
#

locating those in /root is just for the guide demo

#

you can locate them in your user folder if you want

#

the .py files

#

the systemd unit files need to be located as shown

#

and make sure they reference the .py files in whatever location they are placed

civic rune
#

ahh ok, so autoshutdown can be anywhere?

#

as well?