#microcontrollers
1 messages ยท Page 21 of 1
remo.tv would be the easiest for sure
Other people will be able to control the car too.
although I believe there is a private room option too
They have support for certain motor controllers, there is a custom hardware file you can use to set up your own motor controller.
it's on the github right?
glad I could help. Let me know if you need any help setting up the remo software.
ight thank you so much
They have a good discord server too.
Can someone please lend me a hand with a micropython esp32 build? i cannot for the life of me get the toolchain working
What should i use an arduino or Rasberry pie for my rc car
I am using python
or Cython in arduino
Depends on what you want to do
Maybe I can help you.. What is the problem?
thankyou, basically i want to build a version of micropython with mcpwm built into it. theres a github for it but you need to build it yourself and i cant get a esp-idf toolchain working on anything (linux/windows). i was wondering if anyone here had done it before.
What's the error
have you tried to use esp-idf alone without mcpwm or micropython? is it working?
hmmm...actually mcpwm is part of esp-idf. Have you tried any of the examples...like this one? https://github.com/espressif/esp-idf/tree/master/examples/peripherals/mcpwm/mcpwm_basic_config
MicroPython is implemented on top of the ESP-IDF, you should be able to use this mcpwm api
can anybody send me an invite to the ArduPilot discord?
@reef brook if you have an specific repository for you project I can try to compile from my side.
thankyou! that would be a massive help, it's not really something i wanted to get into.
https://github.com/bskp/micropython_esp32_mcpwm/tree/dev-esp32-mcpwm/ports/esp32
i ust need the esp32 one making if you can ๐
Compilation worked fine here. I was able to generate a firmware binary from this repo. The step-by-step is a little bit crappy, but in the end it worked
Can you send the error that you had experience?
I'm currently compiling that on a ubuntu machine
thats what i got in VS Code, the in ubuntu i got maybe 15 errors. i got stuck on click.py not installed. but it was installed and i couldnt make it find it for the life of me
I had to create a virtualenv to install all dependencies from esp-idf
as you can see on my screenshot
I didn't use cmake...
I have used plain make
Also, I have used IDF v4
honestly im not used to linux at all this was my first time using it pretty much i tend to do everything on windows
It should work on windows as well
i know i used IDF4, instaled all the prerequisites, then the idf, then the requirments.txt stuff and it still had alot of issues
did all the git checkout to make sure i had the correct versions.
i tried following some tutorials but i ust thought they might be outdated and thats why
can you try to use make inside micropython_esp32_mcpwm/ports/esp32
?
if the idf.py is in your path and you did all those steps it's supposed to work
try this first
hold on i just need to reinstall it... i deleted it in rage last night
hahaha, no problem
did you already have the idf installed then ?
yup, but i did the checkout to the requested commit hash
okay last night when i went to install it it said some things couldn't be found from the prerequisites. when i get to them i'll let you know
sure, no problem
okay so im gonna follow this word for word
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-setup.html
i've installed the toolchain and idf now according to their instructions and il try make it now
did you do git submodule --init?
yeah :/
so i installed it and now it says it needs installing again ๐
yup, that is expected ๐
now you have the idf.py tied to your current session. If you close your terminal you are going to need to use the export.sh again.
you can go to micropython_esp32_mcpwm/ports/esp32 and try to make it
you can use just make rather then cmake
it says i need a CMakeList.txt
which i guess is for the cmake bverison but you didnt use that ?
you env variable is pointing to a different esp-idf repo
echo $ESPIDF ----> Should point to $HOME/esp/esp-idf in your case
but it seems to be pointing to $HOME/development/esp32
cd /home/development/esp32/esp-idf
./install.sh
them
source export.sh again
this install.sh should create those folders
i dont even have a folder called development
shall i install the esp idf there?
make the folder then reinstall it all there
@quasi spire any chance we can chat screen share it might end up quicker?
yup, I think it's easier
But, I can't do it right now
:/
ahh okay when are you free?
not sure winch timezone you are...but i need +2hs
I'm working right now
kind of working...hahah
ahh okay im in UK hbu? my work is the same if i was at work i would still be doing this
i'll still be up then normally up till 3am working on this anyway ๐
I'm in brazil.
Ok, sounds great them
I'll ping you when I`m availb
awesome thanks ๐
Hey! @reef brook i'm ready
Actually im ready now ill be in Code Help 0
I wonder what happened to https://www.reddit.com/r/micropython
i need some help with arduino ide
i created a simple header file in the new tab
in this header file im creating an class
now i cant create an object of this class in the ino file
@humble kraken Huh that's odd. Maybe they had low traffic and chose not to staff it in favoring of staffing their own forum?
@errant wigeon clearly circuitpython stole it 
how do I connect my raspberry pi to my pc, many tutorials just skip it like its no big deal but how
Connect for what purpose?
You can SSH into the pi to connect to it and use it from your computer. You can get an FTDI USB board and connect to it using serial to send two way data.
what is SSH, im a begginer ๐ฆ
i need to isntall raspberry pi os onto the pi
You would download the raspberry pi OS image and flash it to the SD card connected to your computer, and then plug the SD card onto your pi
From then on the pi is a full computer you can connect to your monitor, mouse and keyboard
i already downloaded it
It's an "image" of the OS in that it's a full snapshot of a working OS
my micro sd card not showing up (i didnt plug it in or anything)
So plug it in?
The SD card
its a micro sd card
Yes, plug it into your computer
If you only have a normal SD card slot, you can get an adaptor, or you can find another computer which has a micro slot
Most new laptops have a microSD slot nowadays
i plugged in my micro sd card into my brothers laptop.
guess what it did
it blacked out the screen and he cant come back in
why did it blackout his screen
i used a type-c card reader
please help ๐ฅบ
@ashen dock 95% of people that bought a microsd card have one of these too https://cdn.shopify.com/s/files/1/0906/7602/products/sandisk-extreme-micro-sd-card-64gb-with-sd-adapter-2_600x.jpg?v=1613099624
the top black bit
that lets you plug it into a normal SD card slot
if you think the USB-C reader should be working normally just try it with another computer
what do you mean by better ? ๐คท
what do you mean by arduino ? ๐
From which project ?
STM32s are basically objectively better lol
Nowadays they are superior in basically every way including price usually, and nucleos support Arduino libraries
(not that you would use them)
So I'm having trouble setting a static IP on the new Raspbian. Can anyone please help?
my "etc/dhcpcd.conf":
interface static_wlan0
static ip_address=192.168.1.23
static ip6_address=<address here>
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
any ideas?
what's the trouble
am i doing something obvious wrong?
got it, another device was using the ip, i'm dumb
lmao
i need help
how do you use python on the raspberry pi
like I know importing libraries and stuff but
what intermediate projects can you really do with it
plz reply so I get an @
@rapid escarp what kind of projects are you interested in? A raspberry pi can run most any python code you can write, but it's small so it might run out of memory or be slow if you ask it to do heavy lifting like machine learning
I have a pi 4, am pretty much proficient with python now (not a programming god just know how to use the language), and I want to learn how do stuff like attaching sensors and learning how to do the cool projects I see online in reddit and stuff
Desk of Ladyada - It's a Keyswitch Cornucopia plus Stemma Sunday https://youtu.be/_Q4SqlQpvOo
The Great Search - Resistive touch screen driver replacement for STMPE610/STMPE811
https://www.digikey.com/short/7mt7b04f
A week or two ago we showed off some mechanical keyboard ideas we had. Well, prototypes came a few days ago and we quickly threw together prototypes for the individual MX/Kailh breakout and a dual-key FeatherWing. The reverse...
@stuck thicket why are you spamming ur live randomly
Actually, @stuck thicket is an awesome place to find pi projects!
One second to pull it up
They have a learn page that's an amazing starting place
thanks ill check it out
im planning on getting a 30 dollar arduino kit from amazon with an ultrasonic sensor. would that work with the pi too?
@errant wigeon
Ehh, yes and no. The ultrasonic sensor uses 5v logic, the pi uses 3.3v logic. You can get away with it by adding a resistor to help protect the pi. Give me a moment to find an example that does that
(but don't worry about it being the right part, everyone slowly builds up a collection of electronics from various projects, and when another project in the future comes along you'll have a part ready to go)
https://tutorials-raspberrypi.com/raspberry-pi-ultrasonic-sensor-hc-sr04/ here's an example wiring
so i would need a 330 ohm and 470 ohm resistor
im not sure how to tell if that's included in that amazon item i just showed u
That looks like a solid kit--and it looks like it's got an HC-SR04, which is the same sensor in the tutorial
IC 74HC595 resistor
So what you actually want is a voltage divider, you have some wiggle room when it comes to those
voltage divider
ok
oh ok so you just make the voltage divider circuit
using resistors
bingo!
your example image uses a 10k and 20k resistor, this tutorial uses a 330 and a 470 resistor
would I need to buy a different resistor?
cuz im pretty broke as a teen i can only buy that one kit right now
I'll bet you can make due with that set
ok thanks so much
if you have 3 of the same resistor, lets say 10k, you can make a divider by sticking the three in a row
if you sample at x:
5v- [10k] - x - [10k] -[10k] - GROUND
it's the same as:
5v- [10k] - x - [20k] - GROUND
that makes sense
which is a nice introduction to resistance in series
Regardless, you should be able to make it work.
so i could make that work with whatever resistors I have as long as I put the correct amount
With some handwaving, yes. There's some issues, but you shouldn't run into them with a pi and that kind of kit.
ok
last question
how would I tell the specs for a 330 or 470 resistor
in ur example u referred to the resistors as 10k and 20k
Resistors use something called a color code: https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code
does k stand for kiloohms?
Kilo ohms, but yes. Most will be 4 bands: three to say the value, and one to say the tollerance of the resistor: how accurate to the previous three bands are to their measured value. There's also a maximum amount of power they can take before the blow up/melt, (really just break, it's not going to blow up, but it might get super hot)
and how would you know which corresponds to which? btw can i friend u so if i need help with something u can help me out? thanks for the help ๐
Actually I might have misspoken--it's been ages since I've had to worry about tolerance or power rating--give me a minute to pull out some old stuff
sure
Right I did misspeak--The fourth band is the tolerance, not the power rating
Unless you're working with sensitive things, you don't usually have to worry about it, a pi isn't sensitive enough to really worry about it
thanks for the help
No problem. Feel free to reach out in the future, but you're probably going to get faster help in this channel than by dming me directly
this is a question u don't have to ask: what education level are you currently at? I'm in my freshman year of high school and I just want to know to see how I stand against someone very knowledgeable about this stuff
A bachelor's in electrical engineering probably given their username lol
I've completed an undergrad degree in electrical engineering, I've been doing contract programming for the past few years, and am looking to go back and get a graduate degree myself.
@sturdy ridge haha spot on
You're exploring electronics and python at a way earlier age than I ever did. That's impressive from my point of view. But never worry about comparing yourself to others--it doesn't help. Just make sure you're happy exploring what you're interested in, and you know what next step you want to take.
Cheers!
I didn't even start electronics or python till first semester tbh
im trying to figure out my interests lol
like i want to do something in math cuz im like 3 grades ahead of my peers in math and im also good at programming
Everyone has such unique paths to this section of python, I love it
@rapid escarp That's awesome! If it keeps you happy, keep at it! There's a huge world to explore
i was thinking of cs, but i dont want to be depressed working a 9-5 for the rest of my life
thanks
im still doing competitive programming and i find it fun, but i just don't want to end up like how most ppl would following cs
There's nothing depressing about 9-5
It's just the times you work
You have to work at some hours of the day
9-5 is why I'm looking at being done with contract programming ๐
I like that consistency
9-5 is great, doubly so with some flexibility
hmm i didn't know that
For sure. And everyone has different lives, schedules, goals, etc. And those change with time too. What might be a perfect schedule for one person might not work for another person.
yeah im currently exploring so many things at once. I'm learning how to program an android app, im starting to make python projects, and im learning video editing for a yt channel
guess i just continue exploring
What's important about work is the work you do + work culture, the exactly times are less important and they just need to fit your other scheduling requirements (exercise, family, etc)
9-5 copying data from one spreadsheet to another is a lot more boring than 9-5 making robots
yeah that is true
how would I start learning about robot development?
would learning how to make circuits and stuff like that only be useful in electrical engineering?
Learn electronics properly, learn some mechanical engineering stuff (CAD, machine design)
Works for the first year and a half of an electrical engineering degree
@sturdy ridge tysm
I am very new to the Raspberry pi, in fact this is my first time working with it. I have a some questions that I really need an answer to:
do I write the script in the IDLE and run it from the terminal
I want to use the Cloud Speech API so I want someone to explain to me how to use it in the Raspberry, how do I code it, and I want the result that I get in the end to be displayed on an LCD Display, how to do that
I have alot of knowledge in robotics but I never touched a raspberry
I would extremely respect if an experienced robot builder gives me some help for my project
You can write them in idle, or from any text editor you like. It's a normal computer. Once you install the OS on the SD card, you can connect it to keyboard mouse and a monitor and it works as normal
How can I help
how do I change the raspberry pi camera resolution?
Okkk, thanks for the help mate
And do I run the code from the same IDLE where I coded it or do I have to go run it from the terminal
doesn't matter, it's just like anything else in python. You can run it from the terminal, or from your editor
I'm wondering how to connect my 1.8inch lcd with my micro:bit controller like this
like what
wdym?
Oh
Like the picture bellow
You see how it has LCD1IN8 under math
I can't find an extension for it
Oh wait
I found it
hey, where can i learn Arduino from the scratch?
The way I learned, and still learn, is to just google exactly what I am trying to do.
You are probably working with some sort of sensor if you are using a micrcontroller so start by googling how to set that up
and how to upload code to the arduino of course
How would I go about being able to transmit data along a usb cable that could then be picked up by a raspberry pi? Using primarily python.
Because I want to make for example, a ldr component that returns data on light intensity
I've seen some stuff in serial data but have not fully understood it yet
Transmit data to a raspberry pi?
From your PC?
You need a UART to USB adaptor, then enable the serial port within raspi's config, and just connect the two
Find the corresponding com port (windows)/tty port (Linux/Mac), use pyserial to open it up and send data over it
Use the raspi library to read from serial
The raspberry has USB ports so it has uart to USB adaptors inside.
You just need to configure the serial port and enable it. You can connect a modem to the usb and use internet thru the USB configure the modem with the serial communication and enable with ipconfig the port for Ethernet.
Is there a way i can control relays over a really simple website hosted on a Raspi?
it does not
raspberry pi usb ports have no ftdi chips, they're mostly just for power
you need a separate adaptor
yep, take your raspi, connect a pin to a transistor which flips the relay, add a protection flyback diode/capacitor
do the rest as usual
i would use an nRF24L transceiver and not even bother fiddling with the USB. If all you need to transmit is sensor values, the basic libraries that nordic provides will work perfectly.
Unless I'm reading this wrong, it still asks you to use an adafruit "console cable" https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget which is USB<->UART cable
@tall goblet
you're reading it wrong, it uses the FTDI first to setup the pi because it's a pre-W version
but I realize it's not actually relevant to the discussion, or more accurately I'm not sure what the original poster wanted to do
also I deleted my post when I wanted to edit it, great job me
either way, this is for controlling the raspi terminal over usb right?
not for transmitting general data like you would on normal uart?
yeah, I think the original question was for reading a sensor through USB
to which I say: read the sensor through GPIO
have to get the data to the computer somehow
that waw my understanding as well. i wouldnt touch the USB ports for that. use a wireless transceiver.
that's what I don't understand in the question
Why not?
It's a pretty common setup even
Generally it's a microcontroller not an SBC but it's a common DAq type setup
I did this a couple weeks ago with an STM32, which did have ftdi over the usb
USB is too finicky and complicated when you have all those pin headers right there just asking to be used.
We're talking about uart, it's nowhere near as complicated as any wireless setup
also what do you mean by "those pin headers"
the question states "data that could be picked up by a pi" so I assumed the PC receiving the data is the pi, and the data is the sensor light detection
pretty sure they want to connect their PC to a raspi which is connected to a sensor
if the computer is a PC, I would connect the sensor to a microcontroller (like a pi pico) and transmit the data over USB via the pico's ability to present as a serial port
data that could be picked up by a pi -> the sensor data, being transmitted over a USB
they probably only have a raspi
and a raspi works fine for the job, no harder than an mcu, you just need an ftdi usb cable
(assuming you don't have real time sampling requirements)
then you are restricted to within physical reach of the PC
it's a data acquisition system, you're almost always limited to the physical reach of the PC in cases you need to use those
he specifically asked for about a usb cable
i'm sure they don't mind a cable limited setup if they're asking for a usb cable
if we go through a raspberry pi computer, I think the serial gadget mode on Zero and 4 can be used for other things than control the pi, but I wouldn't know the specifics, the gadget mode can do ethernet too and then you can use network software and later when you go wifi the code is unchanged ๐
If you use a uart setup, you can easily swap out the uart cable with an HC05 and that will be even less change
nothing changes on the pi side, on the PC side you just have to connect the bluetooth device and swap out the TTY/COM number
many options !
In computer networking, IP over Avian Carriers (IPoAC) is a proposal to carry Internet Protocol (IP) traffic by birds such as homing pigeons. IP over Avian Carriers was initially described in RFC 1149, a Request for Comments (RFC) issued by the Internet Engineering Task Force (IETF), written by D. Waitzman, and released on April 1, 1990. It is...
every part of that article is gold
I just love the tone it's written in
I'm always rolling while reading this part
Thus, this technology suffers from poor latency. Nevertheless, for large transfers, avian carriers are capable of high average throughput when carrying flash memory devices, effectively implementing a sneakernet. During the last 20 years, the information density of storage media and thus the bandwidth of an avian carrier has increased 3 times as fast as the bandwidth of the Internet
Also
In December 2005, a Gartner report on bird flu that concluded "A pandemic wouldn't affect IT systems directly" was humorously criticized for neglecting to consider RFC 1149 and RFC 2549 in its analysis.
Since the developers used flash memory instead of paper notes as specified by RFC 2549, the experiment was widely criticized as an example in which an optimized implementation breaks an official standard.[citation needed]
emphasis added
Hello
:incoming_envelope: :ok_hand: applied mute to @near lintel until 2021-03-23 11:42 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
does anyone have a reccomendation on how get ideas for projects to make
ive been struggling to think of something to make but nothing comes to mind
go to https://www.instructables.com/ or https://learn.adafruit.com/guides/projects and see if somehing inspires you
aight thanks a lot
maybe also https://www.hackster.io/projects and https://hackaday.io/discover and a few more I never heard of ๐
@sturdy ridge Very cool read.
I wish Discord would hit the chat window buffer on a <TAB> key hit and improve the completion. Like get it together lol
ayy yoooo microcontroler check
use codeacademy to learn
ok thx
hi
hi
Hi
How would I go about creating an arduino alarm clock which scrapes audio from the web?
Any ideas?
I was thinking that i could get around the scraping by having my computer beam audio via bluetooth
but i'd still need to store it somehow
and it would also be better to have it self-contained
hi, how can i see information about a pid?
@elder crystal so on it's own, that's a huge project. You'll want to split into smaller projects, like an audio file scraper, and an arduino/microcontroller that plays audio files at preset times. What kind of microcontroller/arduino do you have? Some of them aren't very powerful and have trouble doing too much at once
But this project might be helpful to take a look at: https://create.arduino.cc/projecthub/bitsandbots/making-sound-effects-with-arduino-385e74
@hallow igloo PID as in proportionalโintegralโderivative controller, or PID as in Process ID?
I think if what I am trying to do is see current information about a system user, then when using psutil.user() it shows the users and the user's pid @errant wigeon
Ok that is outside of my wheelhouse, to even take a guess I'll need to read up a bit. Didn't know about the psutil library though, that's a nice one
#unix might have more people who know about it as a heads up
https://psutil.readthedocs.io/en/latest/#psutil.Process So if you feed this a valid pid, you should get the info the system has about that pid--is this what you're looking for?
thanks for the answer ๐ at the moment I have a python audio scraper and some alarm code well underway. I have an UNO, but i'm thinking of getting a mega for the purposes of the alarm clock. Thanks for the link, it looks extremely useful! My main problem figuring out how to get the arduino to webscrape, as I have no experience whatsoever about connecting the arduino to the internet! I'm having doubts about whether I can run all this on the arduino, or whether I should make a computer part for it...
More or less, the arduino won't be able to do that. (There's some major hand waving there, but it's generally true)
a raspberry pi would have an easier time doing it,
the difference is a raspberry pi and an "Embedded Linux" board, and an arduino is a "Microcontroller". There's hand waving, but one can do most of the things a personal computer can do, and the other is built for simpler tasks, like monitor a sensor or turn on and off lights
Now I said there's some major hand waving--and that's because there are boards with wifi and they can be made to crawl and scrape on the web, but due to memory limitations, they're usually only given a small set of things to go and fetch--like the weather
Ah, thanks! That's a precious bit of information ๐ I'll look into raspis for that, as it seems to be exactly what i want. Finally I understand the difference between arduino and raspi! Do you think an arduino could at least listen to my bluetooth input?
Personally I can't say--I've never tried to do audio+bluetooth on arduino. But there's a ton of projects out there that try to do it, so you can get a sense by searching those and seeing what others were able to do
Here's some radio focused ones, https://create.arduino.cc/projecthub/projects/tags/radio
from the looks of it, it's possible, but not necessarily straight forward
adafruit is a great place to search for projects and learn guides on as well
Thanks a ton mate, this is one of the most candid and useful things i've heard ๐ it certainly helped me understand and get further!
no problem! Building stuff is so much fun
hi guys, i have a question that i hope someone can help me solve this problem.
I'm doing my capstone project, the project is about smart door lock using facial recognition. I have already built the API using Flask and OpenCV for capturing faces and training. After that, I don't know how to put the model to the Raspberry Pi for facial recognition. If you have any ideas, please let me know. Thanks for your help guys.
is there any reason you can't just install opencv and flask onto the pi and run it there?
If I turned off the Raspberry Pi so that I can not get the API request from my front-end website dashboard
So I separated it, the raspberry pi only to get the model for the facial recognition
Ok. I need to get a mental picture of how you're designing the program. I assume you have something like [camera]-->[facial recognition]-->[lock] as a rough outline: is that correct?
I will describe my project:
- Front end dashboard website: I use ReactJS, Firebase to store the information about the user, call the API from the server to capture the face of the user
- Back-end server: I use Flask + OpenCV to create the API for capturing the faces of the user, training and export the models (recognizer.yml)
-> I just don't know how to put the recognizer model to raspberry pi
I already have an idea that after training the model, i will put the model to firebase storage.
The raspberry pi will download the model and load the model for facial recognition. But what if I add another person -> This is the problem and I don't know how to solve this
Are you training the model to notice your face from others, or are you training a model that can notice and distinguish multiple faces?
I'm training the model that can notice and distinguish multiple faces. I use LBPH opencv to train
awesome, give me a few minutes to scan through the docs, but it might output some profile array, and to add a new person to the system you might just be able to do something like have a list of all faces, and then the pi will check back in to see if it's list is up to date
okay thanks for your help. Please let me know if you have any idea
so is there any reason you can't have the pi check the firebase storage for a new yaml?
because the thing outputs a yaml file, you can automatically upload the new yaml to the storage server, and every so often have the pi check to see if it's yaml matches the servers yaml, and if it doesn't, update it's own yaml
Can you show me some tutorial how to do that, or you can show me the way to do that things ?
well how are you going to get the yaml from firebase to the pi in the first place?
it'll depend on that process
def download_model():
try:
storage.child('model.yml').download('models/model.yml')
print('Downloaded')
except Exception as e:
print(e)
I have already wrote this function to download the model
awesome! So depending on how you want to handle it, you can do 'model_YYYYMMDDHHmm.yml' where that's a date string, or you could just increase the index 'model_i.yml' for each trained model
then before you download, you can have a second function
try:
# list files
except ...
when you get the list of files, check to see if the new file is more recent than the one you have, and if so, download the new one
def download_model():
try:
storage.child('models/model.yml').download('model.yml')
print('Downloaded')
recognizer.read('trainer/trainer.yml')
except Exception as e:
print(e)
# download_model()
def get_user_by_rfid(rfid):
all_users = db.child('Users').get()
for user in all_users.each():
if rfid == user.val()['rfid']:
name = user.val()['name']
return name
rfid = 0
cap = cv2.VideoCapture(0)
# cap.set(3, 640)
# cap.set(4, 480)
# minW = 0.1*cap.get(3)
# minH = 0.1*cap.get(4)
while True:
ret, frame = cap.read()
img = cv2.flip(frame, 1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# faces = faceCascade.detectMultiScale(
# gray,
# scaleFactor=1.2,
# minNeighbors=5,
# minSize=(int(minW), int(minH))
# )
faces = faceCascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
rfid, confidence = recognizer.predict(gray[y:y+h, x:x+w])
print(str(rfid) + " => " + str(confidence))
if (confidence < 80):
name = get_user_by_rfid(str(rfid))
print('name', name)
confidence = " {0}".format(round(confidence))
count_time = time.time()
else:
rfid = "unknown"
confidence = " {0}".format(round(confidence))
cv2.putText(img, str(rfid), (x + 5, y - 5),
font, 1, (255, 255, 255), 2)
cv2.putText(img, str(confidence), (x + 5, y + h - 5),
font, 1, (255, 255, 0), 1)
cv2.imshow("Camera", img)
if(time.time() - count_time > 10):
pass
k = cv2.waitKey(10) & 0xff
if k == 27:
break
print("\nPress ESC to exit...")
cap.release()
cv2.destroyAllWindows()
@errant wigeon Can you review my code
But what if i run this application, i don't know how to download the model at the same time the application is running
so this code runs on the pi?
Yes this code runs on the pi
and you run this infinitely (so long as you're running the demo at least?
@errant wigeon yes i run this application infinitely
ok, so in that while loop, you could have a check to see if so much time has passed, (like a minute, three minutes, five, etc: that time is how often you want to check for a new model and you want to make sure it's decently infrequent so you don't annoy firebase)
if that time has passed, run the "check for new model" function, and if it does, run the "download model" function, and then you'll need to make sure you update the recognizer with the new model
Thanks for taking your time to solve the problem with me. I will try to implement your idea. If there is any problem, can I contact you for your help through this channel ?
you should be able to ping me here without an issue
best of luck working through the design!
hi guy im a dog and im gonna dead
Generally no
why
micropython is an implementation of python 3 that is implemented on a bare metal level of a supported microcontroller. Python libraries aren't implemented the same way, so a lot of what they require isn't implemented or available in micropython
it aims to be as close to a standard version of python as possible, but you'll hardly ever have more than a few megabytes of space for all of the programs on a microcontroller, so you have to cut out some stuff
kinda.
It might be easier to think of it as micropython isn't python, it's a different programming language. So like you can't just import numpy with a java program, you can't import numpy with micropython
micropython just aims to be as close as possible to python--they follow the same syntax and program structure and execute more or less the same way
Microcontrollers are bare metal. You have nothing available for you until you implement it yourself, no memory allocation, no kernel, no nothing. Most python libraries will depend heavily on the existence of memory allocation and kernel/OS features provided by your operating system. Because a microcontroller doesn't support those, in general using a language on a microcontroller is vastly different from using it on a PC user level environment
so if you want to run a while loop, both micropython and python would be written in the same way
i = 0
while i < 10:
print(i)
but libraries aren't just simple code like that, so they don't 'drag and drop' into micropython like a simple script might
This is true for non python languages too. When you're using Rust, C++, and C, you won't automatically have available to you basic functions like printf and Mallocs and whatnot because they're heavily OS platform feature dependent
Even though unlike micropython they are the same language and implementation
Hi,
I got an idea for a development and I may need 7 microcontrollers. Though I wonder what is the best way for doing that.
Here is the context and the idea:
We got six builings and one underground parking lot that are all newly built, and power may shut off at any time without notice.
The idea is to get 7 microcontrollers: one for each building and the parking lot (so 7 in total), that ping a server (may be PHP server and/or a Python-developed Discord bot), via WiFi.
Here is already a SPOF: WiFi routers may lose internet connection without notice either but still being powered, but I guess that if one router loses connection, the microcontroller would just have to connect to another router. The internet connection is reliable and uses FttH for everyone, but some router models are old and just need to be restarted manually once a month I would say.
When the servers are not pinged after 2 minutes, a webhook from the servers send a message on Discord, saying that power may have shut off.
So far I only know Python as a beginner. I began to learn about 3 month ago, and I just started discovering classes, though I code and improve the Discord bot almost everyday because it has a lot of APIs.
I wonder whether a microcontroller would be appropriate for that?
Here is what should be reckoned with:
- The microcontroller should have WiFi. It will be connected to the ISP router of a neighbor.
- It needs to be powered at all times, so we may need to acquire USB cables and power adapters.
- It will be located in the technical duct of each building where there is a power socket. But that power socket may be used for other purposes, such as powering a vacuum cleaner. The power socket has a European format (French, type E).
-> I am trying to estimate the cost of the project, so the cost can be borne by the home owner association.
Do you have any idea of appropriate hardware for that? can that idea be improved?
I do not know if an ESP32 can do the job? or a Pi Zero W?
yeah I think an ESP32 board would do the job
you might want one with a good wifi antenna or the possibility of adding an external one, to make sure it has a chance to see a router
and you'll want fault-tolerant software that will recover from losing wifi and be able to switch networks
how do I listen to sound on my Pi4? I tried plugging in headphones, but I'm not sure which jack I should put it into, and if this is even possible. Any help?
Thanks!
I'll have a look into it, and MicroPython does not seem too different from Python
Does anyone have a turtle bot? need help with a project
To answer your question,no i dont but are you working on ROS?
yeag ros and lab view gazebo
all the hardcore stuff
where are you learning ROS from? I believe you are pursuing robotics?
@hallow igloo
Not sure if Im asking in the right place, but Im looking for a hardware button that would allow for a half press
Not quite sure where or how to find one, I need it for a half press to trigger autofocus on my camera, and a full press to trigger the shutter release
It's not the best option, but this might be a good starting point: https://forum.arduino.cc/index.php?topic=729004.msg4905175#msg4905175
@olive totem this might help, but it might be far easier to make a design with two buttons unless you need the focus and shutter trigger on the same button
Im taking hundreds of photos in a span of a few minutes, its for photogrammetry, so the focus and shutter need to be on the same button
Also, that design is currently what Im looking at with my own trigger, but its not a very good button, nor is it small enough to fit on my rig in a comfortable way
As an idea, I need a small button to fit on these side handles
And this trigger unit I have is too large and the button too poorly designed https://i.imgur.com/nCuPNk3.png
Ive found some monetary push buttons on amazon, but I really have no clue if they will do what I want
5Pcs AC 250V 2A / 120V 5A NO/NC SPDT Momentary Push Button Switch: Amazon.ca: Tools & Home Improvement
So unless I'm really reading that button wrong (which is possible) those are only one level push buttons
honestly, the adafruit's discord might be the better place to ask--you might be more likely to get someone who's done a project looking for a product like you are
there's a help channel, 'help-with-project' and I'd recommend you try asking there
yo i want to run a block of code randomly btween two midnight any suggestion?
HELLOOOOOOOO has anyone made a micropython byte interpreter so I can have instructions as bytes and potentially store more instructions?
Thanks, Ill take a look!
@olive totem Have you considered the apple approach? Instead of a real button, some sort of pressure sensor with a vibration motor?
Less pressure -> half press, more pressure -> full press?
My honest thought was a momentary button with a metal casing--and a capacitive sensor watching the casing, and gpio watching the button itself--focus on touch, picture with button press. But that's a lot of fiddling to get it up and running
what would be the best bluetooth library for Raspberry Pi?
my test case needs to advertise the bluetooth and let the phone connect into it and send back information
Hey there, I'm writing a Python wrapper to provide a simple API interface for talking with some hardware.
I'm seeking an opinion on if this is a good use case of @property decorators or an abuse.
The hardware are some pumps, and they can respond to some pre-defined commands and give back some ugly strings in the form of bytes. I'm trying to handle that encoding/decoding/parsing process behind the scenes in the wrapper.
I have some methods such as
get_solvent() and set_solvent(x) and I'm considering using @property and @<property>.setter decorators. However, the accessed/returned value isn't being stored on the object. A call to get_solvent() sends a command to the hardware, parses the response, and returns a value. This takes non-negligible time as there is a soft-coded minimum 15 ms delay between sending a command and getting the response.
Does using @property decorators for something like this constitute an 'anti-pattern'? If you used a library that had implemented properties in this way, would you find it smelly?
If this is better suited to a different channel I'll move it
Probably not meant here but my opinion is that as long as it works the same as if it's stored on the object (no funny behavior), it's fine to use as an abstraction
Thanks for the feedback!
PyBluez works fairly well. Make sure you install libbluetooth-dev before attempting to install pybluez (the documentation should be pretty clear on that: https://github.com/pybluez/pybluez/blob/master/docs/install.rst)
How can I communicate with a low power device (room thermometer) that emits a signal at 433ghz
Are you sure it's 433ghz, not 433Mhz?
Yes youโre right sorry
Ok, I've never used them so I dug into it, and I have no idea
There could be encryption: https://www.reddit.com/r/AskElectronics/comments/49swrs/how_does_the_pairing_work_between_433mhz_devices/
but there is a helper library http://www.airspayce.com/mikem/arduino/RadioHead/
it should be possible to figure out how it's encrypted and then use another module that just decodes it, and transmits in the correct for of encryption, but that'll require a bit of reverse engineering and it depends how into the weeds you're willing to get to figure that out
i did some more googling and apparently there is a community around โlow power device transmitters and scannersโ. On the 433 frequency is typically fobs and weather stations (which is the device that I have)
it looks like i will need an SDR receiver, and some open source software.
the receivers i've seen so far are too expensive (at least for this project).
but you're right @kindred sand i could use RadioHead along with Arduino & setup a cheap receiver
That's good to hear, I wasn't sure what you were trying to talk to so I could only get so specific. The SDR is a great choice, there's a large and active sdr community out there, so if you go that route I'm sure there's folks who can help you out
And if you google the device name + arduino, or +SDR you might find a project someone else did that you can simple copy to help guide you
Best of luck regardless!
i'm trying to get data from my weather station device and create reports, check my indoor temperature from work, etc
I'm going offline for a while so I won't be able to reply, but what kind of weather station do you have. That'll can help narrow in on what kind of radio and protocol they're using
https://hackaday.com/2011/06/13/reverse-engineering-wireless-weather-stations/ something like the one in this?
which ones specifically?
here's a cached version of 'if he could only get his hands on the data' https://webcache.googleusercontent.com/search?q=cache:tLCUxopIcesJ:fredboboss.free.fr/articles/tx29.php
i thought this video was pretty cool : https://www.youtube.com/watch?v=JdzVIjKA68o
US: https://www.amazon.com/shop/techminds
UK: https://www.amazon.co.uk/shop/techminds
Here we take a look at decoding some of the micro transmissions from Low Power Devices on the 433Mhz band using RTL433 software for Linux and Windows.
Github Source: https://github.com/merbanan/rtl_433
Windows Binary: https://cognito.me.uk/computing/windows/...
Neat I'll have to take a look at it in a bit. You have a good one and best of luck on this project!
thanks cheers!
damn this is pretty cool
@digital fossil sorry false alarm
false!!!!!
guys I've been quite interested in this field and i just wonder where should i start
i have somewhat of an intermediate knowledge in python, currently getting used to java and am a cs student if that helps
What kinds of things do you enjoy
this offers plenty of different guides and tutorials
well i dont specifically know but ill check that out
i just want to get a deeper insight tbh
i looked into basic projects like building drones and radio frequency stuffs
start simple, writing code to blink an LED is a common starting point, and the joy of getting it to blink after a lot of time trying never goes away
but like with microcontrollers its only smthn you look into when you need something specific no?
ah so what would you recommend i get hardware wise
ehh yes and no, they're not like computers so they can't do anything and everything, but they can do a lot of types of tasks. They're just best for one (ish) task at a time
Have you ever used a raspberry pi?
funny story a while back i did a bit of research and got my hands on a raspberry pi model 3b +
that's an embedded linux device, not a micro controller. But it'll give you a chance to play with some level of circuitry using the GPIO pins
i got an sd card and tried to get it to work but idk i kinda had some monitor connectivity issues
that or i went wrong downloading software
but in hindsight i should've got an arduino instead
its an atmega 32 or something which im pretty sure is a microcontroller
Both the pi and arduino are solid ecosystems and solid choices, I'd also suggest the circuit playground express https://www.adafruit.com/product/3333 since it's got a lot of parts preloaded onto the board
ah i do actually have some softwares that i've demoed with a few components and stuff
fritzing and this other one that was part of a 3d modelling thing
nice! I say find a simple project that sounds interesting (like blinking LEDs or reading the temperature of the room) and work towards getting that up and running
ok thanks ill do a bit more research and try and get to it asap!
it's really also bc i have an a level course in electronics starting this sep so im quite excited
i feel like i dont know enough to be able to start a project tho ๐
then don't start a project just yet. First, try to blink an LED. Then, try to make it blink faster, slower, longer, or shorter
slowly build up to a project, but don't yet start on it. You'd be surprised how difficult blinking an led might be, but that you can do it. Then afterwards, you'd be surprised at how easy starting the project can be in contrast to the difficulty of blinking the LED
You can do it with an arduino, raspberry pi, or circuit playground express
for the circuit playground express: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/red-led
ah ok tysm!
I think the circuit playground is a good board to get over the arduino if you don't already have breadboards, leds, resistors, etc
it has a bunch of stuff built into it so you don't need to worry about wiring just yet
i will try it with the raspberry pi and just get a resistor and led
ah yes thats what i wanted to say
Awesome! Good luck!
basically you see with soldering, i dont want to start yet but theres many different contradicting recommendations out there and i just wanted to know what you would recommend or use
to avoid soldering, you can use a breadboard (a lot of people use breadboards while developing a circuit or testing components-I have two within arms reach of me right now, about four more scattered about my office)
it's a collection of sockets that you can plug wires into, and some of the rows are connected (the above guide explains it far better)
oh i've actually heard of them before
but that wouldn't necessarily work with smd components right?
you then can use jumper wires to jump one connection to another
Correct--smd is tinier and doesn't have pins that can fit into breadboard sockets
but if i were to use a breadboard w jumper wires and components how could i power it
im assuming a 1.5v cell?
so as long as you don't have many components, you can power it from the microcontroller you're using
There's some handwaving there, but for blinking an LED and some other things, you won't need to worry about it yet
a lot of boards have a 3.3v or 5v pin that can supply some current, and most of their gpio pins can also output an amount of current (not as much as the power pins, but plenty to drive lower current devices
The raspberry pi 'blink an led' guide goes into more detail, and adafruit has learn guides explaining it as well
oh ok thanks that is all for now
hi i have this problem on my d1 mini (esp 8266)
it works on another sites
For server i am using fastapi (python) and d1 is running micropython
@last yoke looks like you have a quite old version of urequests on the board
Seems like i have v0.6
maybe you should remove the "#" at line 82 to see what happens and tell us
problem is i am using only screen command to interface with esp. Somehow i have problems with thonny (only program that i know for micropython), so idk how to edit it.
then tbh you should learn about uart / ampy first before trying to debug remote code or you will hit a wall
also i think eric-ide https://eric-ide.python-projects.org/eric-download.html has some kind of micropython support
eric - The Python IDE
dunno if remote debugger work with mp but it's maybe worth looking at it or adding it
make sure you are not connected to the REPL with something else, that might be the issue
I don't know if Mu is a better choice for Micropython
I guess you have to try and see
Okay everyone. Thank you very much for your help. Idk how, but thonny managed to connect today and i created new file with code from urequests github. Now it started working and i can get data from my server.
the thing is the only connection to the board is the serial port, so sending files happens through the REPL too via raw mode, when using Thonny or ampy or other tools. That's why Thonny takes over the serial line and switches between interactive REPL and raw mode as needed, whether when managing files or clicking "run".
So if you are connected with screen, or sometimes if you left the REPL in a particular state, Thonny can't do its thing.
When I used ampy way back in the days that was a major pain to me, having to disconnect from the REPL to transmit every file, and reconnect afterwards. Circuitpython (and the ESP32-S2) was a relief in that regard.
anyone knows why the data is the same number that the adress just one line above the data ? (I'm making a pc : 65c02) and sorry for my english ๐ ๐ญ
i'll give you an exmple
here i defined the adresses :
rom = bytearray([0xea]) * 32768
rom[0] = 0xa9
rom[1] = 0x42
rom[2] = 0x8d
rom[3] = 0x00
rom[4] = 0x60
rom[0x7ffc] = 0x00
rom[0x7ffd] = 0x80
with open("rom.bin", "wp") as out_file :
out_file.write(rom)
(it's an 32 bits rom)
and
it gives me that :
... data -> read -> 00 (adress)
... data -> read -> 60 (adress)
... 6000 -> read -> adress
u can see that at the third line i find again 00 60
annyone knows why ?
there's a user interface channel, that probably would be the best fit
anyone ever used blunano??
question: what can I do with micropython on the ESP32S
yes ik its dumb
actually nevermind i dont have any spare
and its hard
Hey all, I'm using a pico running CircuitPython to emulate a mouse HID. Currently, it's showing up as a mouse, keyboard and controller (separate devices). I noticed this thread on the topic - https://github.com/adafruit/circuitpython/issues/1015
Does anyone know a workaround for hardcoding the microcontroller as a particular device? (Mouse in my case)
A couple of forum posts recently have asked if HID or MSC could be disabled for security or device interference reasons. We need some kind of dynamic USB descriptors to do this. https://forums.adaf...
is anybody familiar with micropython?
the line was initializing an I2C pin
I2C object
i2c = I2C(scl=Pin(22), sda=Pin(21)) which are the correct pins
what is the 'id' argument required supposed to be?
I believe it should be the ID of the i2c object you're trying to connect to.
could you try i2c = I2C.init(scl=Pin(22), sda=Pin(21)) (this isn't my wheelhouse so bear with me)
And from the looks of it, you might already have the scl and sda pins defined in you board, (depending on the board you're using) and might simply be able to to initialize an i2c instance without needing to declare the slc and sda pins (assuming that those pins are defined as 22 and 21 for the board)
I think it needs an id for which hardware I2C you are using
like: i2c=machine.I2C(0, sda=sda_pin, scl=scl_pin, freq=400000)
does it allow you to initialize then scan:
i2c = I2C.init(scl=Pin(22), sda=Pin(21))
my_device = i2c.scan()
or does it absolutely need the id before you can run that init?
the id is the number of the i2c bus , also do not use "id" it's a builtin function of Python
@tiny tiger some platform have hardware i2c and others software i2c so you would need to use the specific platform documentation (if any and up 2 date )
I figured it out I think
@spiral sandal was right, 'id' is a builtin function and i needed to use machine.SoftI2C instead of the usual
So is the default in this case 0, or do the different bus's have different id strings?
here id is just the name of the first argument when you are creating a hardware I2C bus
Do various hardware bus's have predefined names?
is it possible to use vscode for python on rpi pico besides C ?
@mild turret you mean micropython/circuitpython ?
there is a Circuitpython plugin for vscode, I have tested it but I don't actually use it so I don't know the state of it, it should bring completion and a button for the REPL. I believe you need to open the CIRCUITPY drive in vscode, then there's stuff at the bottom right and autocompletion
I don't know about Micropython though
@gentle vapor i mean there was only tutorial proclaiming to do rpi pico on vscode but it actually only did it for C
ah
can you use recursion in micro-controllers to perform daily tasks and is it viable?
I am curious
you can perform repeated tasks, use sleep alarms to avoid sucking too much power, and use an RTC to make sure you stay on schedule, what do you have in mind ?
Like I said I am curious and just wanted to know
Hey guys I was wondering if you could help me. I'm trying to get both of my stepper motors to move clockwise and counter clockwise 1 full rotation. When I run the code I use it only moves one stepper motor. I get an error that the "channel is already in use, continuing anyway" which is why my second motor won't move. I don't get how its in use when i named it differently and am using different pins can anyone help?
@cloud wyvern what type are your stepper drivers (and on which mcu), could it be they need to use separate pwm channels ?
@spiral sandal Iโm using tb 6560 and itโs on a raspberry pi 3b+
pi@raspberrypi:~/Documents/RPI_STuff/Code/Python_Code/12.1.1_Joystick $ python3 Joystick.py
Program is starting ...
Not found device in address 0x48
Not found device in address 0x4b
No correct I2C address found,
Please use command 'i2cdetect -y 1' to check the I2C address!
Program Exit.
not sure why im getting this
happened after i duel booted
There are now over 200 boards that support CircuitPython!
https://www.adafruit.com/200boards
Write down the mode 0 control words of 8255 for the following two cases:
(a) Port A = Input port, Port B = not used, Port CU = Input port and Port CL = Output port.
(b) Port A = Output port, Port B = Input port, Port C = Output port
does anyone know this ?
Sounds like you want to look up the datasheet and look for those words
It is on the pages 4 and 5
Should be quite simple
Feel free to ask if there is something you donโt understand
I want to learn hardware programming, but I don't know where to begin... Like serial ports, USB devices... I am a web developer, have any idea what I should work on first?
@grizzled creek if you want to use python and web then maybe you could build a web simulator
this one could use some blinkenleds https://sim.lvgl.io/v7/micropython/ports/javascript/bundle_out/index.html
๐
Can I run python on arduino uno
It is what I have and I can't buy a pyboard now cuz of the pandemic
@lean oracle you'd better use micropython unix + rpc via serial, because uno can only run some bytecode as it does not have enough ram
it just need a very long usb cable ๐
there's also https://github.com/keith-packard/snek but i really don't know how far you can go with that on a uno
Hello are there people here with experience in Arduino (or C/C++ libraries)? I'm trying to write my own class where I want to use another library's instance in that's automatically created on the #include. I haven't figured out how I can use that same instance in my own class.. The class type is IrSend with the instance IrSender, I would like to use IrSender.doStuff() in my library.
Right now I'm getting a ton of errors that say multiple definition of IRsend::functionX. I simply included the library in my custom class and call it like I would in the Arduino .ino file, where it works fine.
you may need to copy C & H content of library (IRremote/src/*) you want to extend inside src folder of the one you are creating so IRremote .c does not get linked twice
hello
does anyone know how to read pyserial data seperately if you don't mind helping
for example x and y axis data at the same time but take those two data as seperate variables in the serial communcation inputs
Hiye
Anyone here know about arduino
cause i have a doubt
This is the code i wrote for a simple obstacle avoider...Im new to arduino and i dont have one yet ...Will this work ...If i connect it to an arduino and the included parts ?
and ignore if i have missed semicolons
And i have another doubt
Can i program an arduino with python without additional hardware
Not really, from what I know you can only use libaries from pythont to get serial data from the arduino. So in ways you can have bit of functionality. But not like fully using c/c++
there are few Arduino products supported by Circuitpython (it doesn't run on 8 bit AVR like Arduino Uno, Nano and such) https://circuitpython.org/downloads?q=arduino
And many Arduino-like (and compatible) products that support it or Micropython.
Hey
Anyone here know how I can get started with stm32 microcontrollers
I have two stm32 boards
One with stm32f103rct6 and another with stm32f103c8t6
you are can setup project Arduino with python?
Anyone here got exp with Wasp-os?
Oi
anyone can please help me or guide me on how to get serial data on arduino to python
I used pyseriala but I can I make the output's seprate and give them to to different variables ein the python script with x and y delcartions.
it depends of the format of the data output by the board. I tend to prefer using json, it's easy to handle from python, and if it's simple you don't need a json library on the arduino side, just formatted print. You can also use binary formats with python's struct module. If you can't change the format from the Arduino, you'll have to parse it somehow.
Thanks a lot mate
Hello, i'm looking for help with a medical sensor and micropython, can someone help me?
here is the full question:
how can i program a sensor from i2c with micropython? i need help or guide about the creation of own libraries to this sensor, i didn't found basic information to this on google. the sensor is MAX30102 it's libraries are on Arduino and i didn't found micropython version.
And to reduce duplicate effort on the question: I linked this as a starting point guide https://learn.adafruit.com/micropython-hardware-i2c-devices/i2c-main
how can we code arduino with python
@novel aurora just in case, are you talking about my question? Or something apart...
You know Google exists ? https://realpython.com/arduino-python/#hello-world-with-arduino
I love pyfirmatta
Hey
Anyone here know how I can get started with stm32 microcontrollers
I have two stm32 boards
One with stm32f103rct6 and another with stm32f103c8t6
Stm32 microcontrollers
Have you used one of those ?
Ok
I just want some resource to use them
Raised a Adafruit issue: https://github.com/adafruit/Adafruit_Blinka/issues/451
This issue needs to exist for the workaround: ##150 Issue: When I instantiate and utilize the #https://github.com/hzeller/rpi-rgb-led-matrix 50% of the display matrix isn't initialized. Cod...
This is the first time I have encountered a bug that requires another bug in order for the actual intention of the function to work
@tacit swift just grab a cheap STlinkV2 and go there https://github.com/rogerclarkmelbourne/Arduino_STM32
Thank you ๐
I was having a lot of trouble connecting my Arduino Nano to my computer, and I'm not sure if this is the right place to ask for help. It was for a python based code, and a microcontroller, but I don't know.
Trying to use PySerial to write to a STM32F7 disco board, I've basically got a number of this max length '2.1785714285714284' and want to be able to write that serially through USB. I've read the API but am unsure how to implement and use it properly, has anyone got any experience doing this before?
Yes
been playing around with micropython for my smartwatch ๐ such cool stuff!
wouldn't it be with that module @gaunt hemlock
I can use the module, but I will check with django on the site.
no
ok
just receive and send data
great
By the way thank you for not using too many terms because I'm a little too young
I'm not sure for micropython, but if you know C++, then I can reccomend:
https://youtu.be/EaZuKRSvwdo?t=50
and other videos:https://www.youtube.com/results?search_query=sm32+arduino
โโUpload Gerber files for review & order $2 PCBs: https://jlcpcb.com/quote
Support me for more videos: https://www.patreon.com/GreatScott
Previous video: https://youtu.be/BgIjlvlwwzY
Facebook: https://www.facebook.com/greatscottlab
Twitter: https://twitter.com/GreatScottLab
Arduino videos mentioned in the video: https://youtu.be/BtLwoNJ6klE htt...
Thank you @sudden rain
Is micropython available for the ATSAMD51J20A chips?
I see circuitpython is
And I see this https://github.com/micropython/micropython/blob/master/ports/samd/boards/samd51g19a.ld which seems hopeful ๐
Is Thonny good for MicroPython
witch is the best smartwatch to make programs to??
hey
does anybody knows pyfirmata
i programmed Arduino using standard firmata but it works till it is plugged with my pc
but as i unplug it, it stops working
and can you recommend some cheap microcontrollers which can be programmed
using python
my understanding is that firmata is a way to control your microcontroller from a PC, so of course it does not work when unplugged from the PC ? Unless I'm missing something, I'm not sure what you want to do ?
https://www.arduino.cc/en/reference/firmata this i guess
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
If you want to program the microcontroller with python, look into those https://circuitpython.org/ https://micropython.org/
some of the supported hardware are cheaper than others, like the Raspberry Pico
I'm talking about the Raspberry pico, not the SBC raspberrys
they have pretty much nothing in common in the way you program them, the name is just confusing
now sure there are ways to write the same code for both by using the Circuitpython Blinka layer for linux for example, and it certainly can do many of the same things
is python's Curcuit lib is good to use to make drones, or will it have a bad reaction speed
since python is slow I have some doubts
why wont circuitpython stay downloaded on my pico
when i unplug it and plug it back in the circuitpython uf2 file disappears
for Circuitpython help I suggest the adafruit discord, channel help-with-circuitpython https://adafru.it/discord
hey, i have an esp32 with micropython installed on it and a mpu6050 sensor. im trying to read the data off of the mpu6050, but for some reason cant i2c.scan find the mpu6050 sensor.. the light of the sensor is on so i think the sensor is working
does someone here know how i can fix this? or help me set it up
I have a question here -- looking for some feedback on unit tests I wrote for interfacing with some hardware (HPLC pumps)
#unit-testing message
Sorry for the x-post but I wasn't sure where would be the best place to ask, seemed applicable to both
and I also have a question
I want to make a small 4dof robot arm that can harvest a hydroponic bin with the help of a camera
But even though I'm familiar with Python and machine learning, I've never tried training a robot arm by combining inverse kinematics, a camera and machine learning
So do any of you know a tutorial where i could start, or maybe some documentation?
thank you :))
If you google "circuit python/micro python for drones" there's a sizeable number of results. While I've not explored programming a drone, I think it should be functional for them. Now if you're exploring things like drone racing, it might be pushing the speed of the language, but I'd wager it's more than functional for what normal drone flight needs. (Since I'm not experience in drones with circuit python, I'm saying this based off of the results of a google search).
Does i2c.scan not return any address?
The feedback you got under the unit test channel is fantastic, (I gained some tips for future and ongoing projects). The only real suggestion I can offer is to test that certain return values raise errors: there are pressures that are basically impossible to achieve during functional operation and that kind of sensor awareness is really helpful. If a sensor is returning an impossible value, it frequently helps to flag it as erroneous. But honestly, that recommendation is built off of my own experience dealing with poorly reporting sensors, so maybe it doesn't apply in your instance. Other than that and what's already been recommended, the tests look alright when I looked them over
Having a hydropincs system myself, and knowing the roots of my plants get tangled, what are you looking for with respect to harvesting? Different 4dof arms will have different strengths, and might have trouble successfully picking what is ready for harvest. Ignoring that issue, my instinct is to recommend that you use an embedded linux device (or just a regular computer) for all of the machine learning/camera/computer vision stuff so you have access to the full python ecosystem, and then communicate the necessary actions to the arm itself. This approach would help you divide the project into a bunch of smaller steps: interfacing with the arm (the only part that might need a microcontroller), deciding how to move the arm (Which I think would involve a robotic arm simulation of some sort, such as https://github.com/srsanghavi/Robotic-arm-simulation), backprojecting or computing the 3d location of a pixel in a 2d image to figure out where the grabber of the arm needs to be (https://math.stackexchange.com/questions/2237994/back-projecting-pixel-to-3d-rays-in-world-coordinates-using-pseudoinverse-method, https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point/mathematics-computing-2d-coordinates-of-3d-points), and finally deciding the 'ready to pick' threshold of your crop (this is a huge area of investigation in agg research: https://academic.oup.com/jxb/article/67/11/3587/2197789, https://www.hackster.io/taifur/ripe-fruit-identification-9c8848, etc. The keyphrase I searched was, "opencv harvesting crops" as opencv is a great library that has a python extension for these kinds of projects). In short, it's a complex project, but by letting yourself use a computer for most of it, the only part of a microcontroller you need to worry about is how to controller the 4dof arm
Thanks for the feedback!
nope it doesnt return anything or im doing it wrong, but i dont think so
thanx bro
Holy crap this is amazing feedback. Thank you so much kind sir ๐
Hmm. Are you sure your SLC and SDA pins are correctly selected?
Why does binary data being sent over USB data lines sometimes have to be encoded in base64? Like from the raspberry pi pico to the raspberry pi 3b+?
in what software ? what is running on the pico ? on the pi3 ?
I think I can hasard a guess that you are talking about maybe Micropython that would require it because the serial is the REPL console and so binary data could contain control characters that could have unintended effects, but pure serial in like arduino would not have that issue
yeah im 100% sure, i tried swapping the cables for them also to be sure and it still didnt work that way also
Yeah micro python running on the pico sending serial data from the pico through the usb to the raspberry pi 3b+
I think this explains it then, thanks
Also, where did you learn this information from?
KeithTheEE--- can a raspi 3b+ handle OPENCV ? is there a distribution that has this already in its image from the start?
I use Circuitpython on a daily basis (and you can find me on the adafruit discord in the related channels) and even though my knowledge of upstream Micropython is older and spottier, they share a lot
I was even talking about that over there yesterday, as somebody was asking about outputing binary to serial and found it was coerced into string/unicode representation
Circuitpython is now including (in alpha) the option for a secondary, binary friendly, dedicated USB serial interface (as well as treat the REPL serial as binary). I don't know if Micropython can do that too though
maybe Micropython has a way to open the repl serial as a data stream/UART
I see
Question here, "Micropython that would require it because the serial is the REPL console and so binary data could contain control characters". How is serial data stored on the REPL console? Are you saying the REPL console can be used to retrieve the serial data being sent from the pico outward using some commands because I was reading this : https://www.raspberrypi.org/forums/viewtopic.php?t=306520
Then from there, reading that, I'd potentially see some control characters?
ah you see, I didn't know sys.stdout.buffer.write would work ! existed
or is it sys.stdout.write ?
while True:
sys.stdout.buffer.write(a)
There's this example on the site so I'm pretty sure it is sys.stdout.buffer.write
seems like it should work then
I was confused to what he wrote prior a=b'\x01\x00\xff' though?
And I'm a bit confused on the definition of a buffer and how it works here, I need to test this too when my pico comes through I got my raspberry pi 3b+ already
that's a way to define a byte string, you can also use bytes([1, 0, 0xff])
you can create a buffer and write to it rather than allocate new ones
buf = bytearray(10)
buf[0:4] = b"beef"
buf[4:8] = "beef".encode()
buf[8:10] = b"\xbe\xef"
print(buf)
bytearray(b'beefbeef\xbe\xef')
sys.stdout.buffer.write(buf)
now as to sys.stdout.buffer
I think it's basically the way to access the binary underlying buffer of sys.stdout without string conversion
but I don't know more about that
I saw this line of code to be run on the raspberry pi 3b+ which was ```python
ser = serial.Serial("/dev/ttyACM0")
while true:
line = ser.readline()
But there's a gap in my understanding to what ```sys.stdout.buffer.write``` does to pass data along its micro usb port, which will then be moved across to my raspberry pi 3b+ usb port via usb cable
ah well the board presents itself to the computer as a USB-serial device, creating a serial port on the host (/dev/ttyACM0 on linux if no other port is present) and that's how you read the buffer from the host, by using pyserial a in that code, or anything that reads a serial port
now in the example it uses readline()
but you can use read(n) to read n bytes
if you output as binary, you don't want to use readline, that's more for strings
In order to send float data types should I convert them to a string data type on the raspberry pi pico then pass that normally through sys.stdout.buffer.write() then when picking it up via the serial module on the raspberry pi 3b+ use readline()?
I think I remember something about passing float data types or just numbers in general and converting them to string prior is better because of the character set or the lack of unicode support something like that with Micro python idk it was something a bit complicated
ah no we were talking about sending as binary
if you're fine sending as strings you can just print
import time
while True:
value = sensor.something()
print(value)
time.sleep(1) # not too fast !
ser = serial.Serial("/dev/ttyACM0")
while true:
line = ser.readline()
try:
value = float(line)
except ValueError:
continue # ignore bad value
# do something with the value
print("Received",value)
Oh damn I see
So printing automatically writes to a buffer
You talked prior to there being the potential of multiple buffers here? Does reading through serial automatically collect all that data into one then reading from that will output that chunk? Or will you just have to catch the data at different time stamps?
yeah there is no flush needed
by the way for binary something like that would probably work, not quite sure on the details, and I prefer using json in general to transmit data (unless maybe it has to be super fast, but then python might not be the bestest choice)
import time
import struct
while True:
value = sensor.something()
sys.stdout.buffer.write(struc.pack("f",value))
time.sleep(1) # not too fast !
ser = serial.Serial("/dev/ttyACM0")
while True:
line = ser.read(4)
try:
value = struct.unpack("f",line)[0]
except ValueError:
continue # ignore bad value
# do something with the value
print("Received",value)
I mentioned multiple serial ports, they would be completely independent from each other, like 2 separate files you write and read from, it would be /dev/ttyACM1 for example for the second one, the point is to be able to access the REPL to test and debug without interference with the serial data line, but I don't know how to do that in Micropython. The forum thread you linked mentioned it, and there's certainly the answer to that in that forum
(might need a recompile of micropython though)
Hmm I see
Also, there was something I wanted to understand as well it was identifying which of my components are in which port.
I had an idea to read from each serial port on my raspberry pi 3b+ and when I send serial data via my raspberry pi pico I would send the data in a string format with information such as "Component1-x".
With x just being the data collected from a component I'm sending and "Component1" being used when the data is picked up to identify whether the serial port I'm reading from is one of my components. Then from here it can handle the data.
Would this work?
Ah it should I assume, and it would just come down to me testing it first to see if it wouldn't
I would use json:
import json
data = json.dumps({"component1" : value})
print(data)
data = json.loads(line)
if "component1" in data:
print("Component 1 sent:",data["component1"])
it's all strings, but it can do structured data that easily translates to and from python, which is great
(some try/except might be needed in case the json data doesn't validate)
or you can send some fixed size identifier in the binary stream, and read the right number of bytes to test it
what kind of project is that for ?
A environmental sensor. I'll have a casing and screen display for my raspberry pi 3b+. The display will have a pyqt5 window that displays data collected from the serial ports from attached raspberry pi pico components that will read data such as temperature, humidity / moisture, light intensity, etc. It's purpose is to help with gardening / farming
There will also be a casting for the raspberry pi pico attachable components to make the components need and safe guarded too *
very cool
Ty
And thank you @gentle vapor for the help as well, really appreciate it! ๐
Hopefully when I get the pico through the order I can test this and get it working well
Then order a couple more
hmmm is there wifi on a pico?
oh yeah collect data into a python dictionary, populating it as needed, and send that over in json, the pi can then update the display with whatever is available in the dict
no, for wifi you will likely want an ESP32 or ESP32-S2
I see, I'll check that out
pico speaks python that makes it easier
the ESP32 is a very good Micropython platform
it has 2 hardware SPI and 2 hardware I2C
(that can be used on a variety of pins, but read the pinout to know which)
mmmm leds and optocouplers to the rescue
there's a ton of ESP and pico projects out there to look up for inspiration, they are both quite popular
pico = smart node
have your sensors for hydro - local = 3 feet away -- then send data via serial ? I2C ? .... wifi
then have a RP3B+ run 24/7 and do data logging and messaging( basement is flooding - ALERT )
ESP32 is the new version i guess
hmmm
which arduino kit is best for home automation/Ai?
For interfacing with nodemcu is there any other dev enviroment other than Thorny?
giveaway? as in you want someone to give you one for free?
yes
Hmm. If that's the case I recommend trying to wire up to the second i2c bus on the esp32: https://docs.micropython.org/en/latest/esp32/quickref.html#hardware-i2c-bus. I have no idea why the first one you're wired to, but since there appears to be the option of a second bus I'd recommend trying that
To my knowledge yes it'll run just fine. If you try to do some extreme computing the pi might lag, and if you don't keep track of your ram you could hit memory errors, but opencv has been compiled for the pi: https://towardsdatascience.com/installing-opencv-3-4-3-on-raspberry-pi-3-model-b-e9af08a9f1d9 (This was written in 2018 so I wouldn't worry about the opencv version they specify, you're probably fine going up to the lastest/default that installs)
cool thanks
Haha, yes๐
@steel folio you can get off brand ardino kits for realllly cheap just buy one of those
I have one
Now I need rasp
Oh I can get a rpi zero for 5 bucks... lol
Either way it's generally frowned upon to go into groups like this and beg for people to buy things for you..
Has anyone here much experience with a 3 x 4 matrix keypad, with the Raspberry Pi?
I have a matrix keypad which is connected to my Pi and is working perfectly as expected in terms of being able to talk to it, it's registering inputs absolutely fine. However I'm having some issues whereby if you hold the keypad button down for any length of time it is registering more than one input as the check is held inside a loop.
The loop part of the script is
if __name__ == '__main__':
# Initialize the keypad class
kp = keypad()
# Loop forever
while True:
# Loop while waiting for a keypress
digitPressed = None
while digitPressed == None:
digitPressed = kp.getKey()
print(digitPressed)
sleep(0.1)
Can provide the keypad class if needed.
does it return one or a list of keys that are pressed ? what you want to do is remember if the key was already pressed by setting a variable and reset it when it's not pressed, and then you can chose to do whatever you want when the key is pressed or released.
So, I have a question.
I want to start IoT.
where should I startโฆ?
I have decent xp in Django and I have also made few projects using it and espโฆ
I'd start by picking a project and searching online for examples of how other people did it. After you do a few basic projects you should have a good enough understanding to make something original
hmmm. IC @harsh kelp.
I have made some projects beforeโฆ
can you suggest what should I give more weightage, networking or the hardwareโฆ?
I'm not sure what u mean by weight age.. but I'd say it's better to start with hardware and learn how drivers and such work. That way when you move onto networking its just a matter of connecting and sending signals
It's hard to say tho it really depends on what you want to do
they're both important, so i suggest learning both
Sorry mate didn't see this - it returns just the key which is pressed, not a list.
Your solution sounds like the best case scenario - do you have any pointers for me? I'm not a newbie when it comes to programming, but not particularly well versed in Python.
What happens if multiple keys are being pressed/held ?
Assuming only one is pressed at a time, you can do it like that.
wasPressed = None
while True:
digitPressed = kp.getKey()
if digitPressed and digitPressed != wasPressed:
print(f"This was pressed: {digitPressed}")
wasPressed = digitPressed
# wait a time low enough for the reaction time the user expects
sleep(0.1)
You might also want keypad to give you a set of what is currently on and do set maths, though if only one can be pressed at a time, you can have kp.getKeys() be set(kp.getKey())
wasPressed = set()
while True:
pressed = kp.getKeys()
for key in wasPressed - pressed:
print("this little key went to the market") # key released
for key in pressed & wasPressed:
print("this little key is staying home") # key held down
for key in pressed - wasPressed:
print("this little key had roast beef") # key just pressed
wasPressed = pressed
# wait a time low enough for the reaction time the user expects
time.sleep(0.1)
Appreciate the response mate, I managed to get it working in the end ๐
I used this
previousKey = keypad.getKey() # Initialise a variable to store the last saved value
while True:
sleep(0.1)
# Obtain the current pressed key
digit = keypad.getKey()
# If a key is actually being pressed
if digit != None:
# Check if the key is different to the previous one
if digit != previousKey:
# Print the number
print(digit)
# Set the previous value
previousKey = digit
๐
can you use python for motor controllers? how does it compare to other languages for controlling hardware?
Guys I am just about to start using the python in microcontrollers, So which library do you prefer and also which microcontroller should I buy so I can run it and use it in my daily life.
Hey @hallow igloo!
It looks like you tried to attach file type(s) that we do not allow (.rtf). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a.
Feel free to ask in #community-meta if you think this is a mistake.
@thin grotto
free shipping microusb cable: 81c
https://www.aliexpress.com/item/4001205517182.html?spm=a2g0o.productlist.0.0.495c71a7HSpoYp&algo_pvid=080be9d6-39dd-4568-9a7e-eb2cd3496728&algo_expid=080be9d6-39dd-4568-9a7e-eb2cd3496728-1&btsid=0b0a555416209927946585211ef7b3&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
free shipping usb charger: 1.19โฌ
https://www.aliexpress.com/item/1005002637573320.html?spm=a2g0o.productlist.0.0.241d651eA5VlgP&algo_pvid=d6d2ba38-0a40-4936-b9af-962fbc453db2&algo_expid=d6d2ba38-0a40-4936-b9af-962fbc453db2-2&btsid=0bb0624716209927403932339e41bc&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
free shipping 32GB micro SD card: 2.80โฌ
https://www.aliexpress.com/item/1005002564683965.html?spm=a2g0o.productlist.0.0.11322b3d2bNlDB&algo_pvid=954afb62-2d5c-46e1-b71a-6d2338a9c219&algo_expid=954afb62-2d5c-46e1-b71a-6d2338a9c219-2&btsid=0bb0622a16209929607877579e4e56&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_
Smarter Shopping, Better Living! Aliexpress.com
Smarter Shopping, Better Living! Aliexpress.com
Smarter Shopping, Better Living! Aliexpress.com
you don't need 40$ for a raspberry pi w setup
wow!
Hm, I've been thinking a lot about those USB wall adaptors, I've been extremely sceptical to the รผber cheap ones because I don't want to burn said mcu and/or my apartment down.
There are some that can be bought in local stores, but they tend to go for prices ranging from 5โฌ to 25โฌ roughly so..
The thing is I would actually love to buy a small bunch (10-20) as long as the price would be around $5 or less
Best language to code microcontrollers is c++
if anybody could come help me out with a question in #help-popcorn that would be amazing
Hey guys, I'm trying to make a box as an object in micropython and display it on an OLED. All other functions are working fine, oled works, tested the lot.
when I press run, this code freezes up and the screen remains blank. Can someone point me to what im doing wrong?
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
import wif
from machine import Pin, I2C
import sh1106
import time
class box:
def __init__(self,x,y):
self.posx=x
self.posy=y
while True:
time.sleep(2000)
display.fill_rect(self.posx,self.posy,10,10,1)
display.show()
def movebox(self,tx,ty):
self.posx = tx
self.posx = ty
# ESP32 Pin assignment
#i2c = I2C(-1, scl=Pin(14), sda=Pin(27))
i2c = I2C(scl=Pin(14), sda=Pin(27), freq=400000)
display = sh1106.SH1106_I2C(128, 64, i2c,Pin(16), 0x3c)
display.sleep(False)
display.fill(0)
r=box(15,15)
wif.wifi_connect()
note: import wif is just my wifi initialization
or wires
u mean USB in voltage socket for a wall?
@sly acorn no, I'm talking about the same sort of adaptor as the one depicted in @hallow igloo 's post
@pure sinew I wouldn't worry about it, the 25$ ones are 99% surely made in china too, you're just paying a premium for sake of giving money away
I can't say I've ever had any problems with articles from aliexpress
ofc you can buy higher power rated ones on aliexpress too, i believe 20W ones will come at around 3$ or so
the one i sent is rated for only 5W but that should be more than enough for raspberry pi
Does it get stuck in that infinite while loop in the box init method?
@mortal plover I was toying around until another user pointed me to the fact that my "sleep" time was in seconds and not microseconds, so my box would take, according to my code above, 33 minutes before drawing the box. I'd slept and woken up to a box on my oled!
I'm having fresh new issues now, like moving a box from a to b
Hey @balmy osprey!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
โข If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
โข If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
This is my new code, could someone look at my box class and see if i've done something wrong? The box class has a movebox function which is supposed to move the box to a given coordinate on my oled screen.
class box:
def __init__(self,x,y):
self.posx=x
self.posy=y
self.update()
def update(self):
display.fill_rect(self.posx,self.posy,10,10,1)
display.show()
def movebox(self,tx,ty):
x=self.posx
y=self.posy
pathflag = 0
if (x>tx&y>ty):
pathflag=1
elif(x<tx&y<ty):
pathflag = 2
elif(x<tx&y>ty):
pathflag = 3
elif(x>tx&y<ty):
pathflag = 4
elif(x==tx&y==ty):
pathflag = 0
while (pathflag == 1):
display.fill_rect(self.posx,self.posy,10,10,0)
self.posx = self.posx-1
self.posy = self.posy-1
self.update()
while (pathflag == 2):
display.fill_rect(self.posx,self.posy,10,10,0)
self.posx = self.posx+1
self.posy = self.posy+1
self.update()
while (pathflag == 3):
display.fill_rect(self.posx,self.posy,10,10,0)
self.posx = self.posx+1
self.posy = self.posy-1
self.update()
while (pathflag == 4):
display.fill_rect(self.posx,self.posy,10,10,0)
self.posx = self.posx-1
self.posy = self.posy+1
self.update()
if (self.posx==tx&self.posy==ty):
pathflag=0
display.fill_rect(self.posx,self.posy,10,10,1)
display.show()
```
what are u saying
I donโt think I know enough about micropython but it looks like once you enter one of the while blocks it will never break out since pathflag isnโt updated until that if statement at the end?
@mortal plover Thanks for checking it out! The final code was way simpler:
class box:
def __init__(self,x,y):
self.posx=x
self.posy=y
self.update()
self.pathflag = 0
def update(self):
display.fill_rect(self.posx,self.posy,10,10,1)
display.show()
def movebox(self,endx,endy):
startx = self.posx
starty = self.posy
for i in range(1,21):
display.fill_rect(self.posx,self.posy,10,10,0)
self.posx = int(startx + (endx - startx) * i/20)
self.posy = int(starty + (endy - starty) * i/20)
self.update()
@gentle vapor Uploaded this to github https://github.com/theaxxxin/micropython-oled-boxes, would you like to be mentioned? ๐
Hey guys, so I've added to my previous piece of code and have a wire attached to my esp32's touch sensor. Is there a way to use the two cores of the ESP32 and listen to touch events?
Or would that be overkill and can I add an event listener on the same core as an object?
I've been trying to port some of the code over from Keyboard and Keypad libraries
while True: # making a loop
try: # used try so that if user pressed other than the given key error will not be shown
if touch0.read(): # if touch is recorded
print('You Pressed A Key!')
break # finishing the loop
except:
break
This was the init
from machine import Pin, I2C, TouchPad
touch0 = TouchPad(Pin(12))
touch0.config(500)
anyone has block diagram for a frequency meter?
@eager wasp Thanks! I'll take a look, looks promising
You're going to want to set a variable then exit quickly then let the main loop handle the input.
@eager wasp Hey so I kinda got what you said, but my code isn't running properly, could you take a look?
button = Pin(10,Pin.IN)
button_press = False
global interrupt_pin
def handle_interrupt (pin):
global button_press
buttonpress = True
global interrupt_pin
interrupt_pin = pin
button.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
instance=[]
boxcount = 0
while True:
if button_press:
boxcount +=1
instance.append(box(random.randint(1,128),random.randint(1,64),10,count))
You need to set button press to false after you read it.
while True:
if button_press:
Oh i see
Also I'd just put like a sleep 10ms timer in your while True loop
@eager wasp Could you check this if you have the time? https://pastebin.com/2r530uXZ It's my full code, I'm uploading what I learn to github https://github.com/theaxxxin/micropython-oled-boxes so that anyone in the future can make use of this
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.
It's not working for some reason
(the pastebin code, not whats on github)
Put the sleep under the while True not in the if statement
buttonpress = True
\
typo
_
๐
And changed this too
In the interrupt handler
button = Pin(10,Pin.IN)
button_press = False
global interrupt_pin
def handle_interrupt (pin):
global button_press
button_press = True
global interrupt_pin
interrupt_pin = pin
button.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
instance=[]
boxcount = 0
while True:
time.sleep(0.01)
if button_press:
boxcount +=1
instance.append(box(random.randint(1,128),random.randint(1,64),10,str(count)))
button_press = False
That looks reasonable.
maybe it's a problem with my OOP
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this is the edited code
I'm trying to remember if you have to reset the input pin after reading it.
The code executes but nothing seems to happen when i press the button
further, in my pastebin, I've made a typo inside initializing my new box object on buttonpress, but the shell doesnt throw up any errors which leads me to believe that the button press code isn't being executed
however the system seems to be in a loop because the shell isn't receiving any input
says machine is busy
Yeah... That's the one problem with ISR's and for loops. They don't exiit.
At 10ms, if you count to 1500, that's 15 seconds?
Just change the while True loop into a for x in range(1500):
Then it should exit.
Give it 15 seconds then try again.
Also print() if you get in either if statement.
Also, are you sure it's rising? or falling?
just for the button
boxcount = 0
for x in range(1500):
time.sleep(0.01)
if button_press:
boxcount +=1
print("buttonpress!")
instance.append(box(random.randint(1,128),random.randint(1,64),10,str(boxcount)))
button_press = False
Got it... I thought the pot was a button as well.
@eager wasp Is this what you were saying?
Does the pin actually match up in software?
That looks right to me.
D34 --> Pin 10
Pin 10 is GPIO25.
I would take a multimeter and find out where that pin goes.
According to that document it could also be GPIO34.
I think in Micropython pins represent the GPIO number.
It doesn't have a clue about how that board is layed out.
Well, the screen wires up fine, had to set SDA and SCL pins
did that according to the diagram that i attached
I'm looking back over your code.
from machine import Pin, I2C, TouchPad
import sh1106
import time
import random
# ESP32 Pin assignment for display (DONT IGNORE)
i2c = I2C(scl=Pin(14), sda=Pin(27), freq=400000)
# Display Init Sequence ----
display = sh1106.SH1106_I2C(128, 64, i2c,Pin(16), 0x3c)
display.sleep(False)
display.fill(0)
# ------
#Box Class
class box:
def __init__(self,x,y,sz,name):
self.posx=x
self.posy=y
self.size = sz
self.name = name
self.update()
def update(self):
display.fill_rect(self.posx,self.posy,self.size,self.size,1)
display.text(self.name,self.posx+self.size+2,self.posy)
display.show()
def move(self,endx,endy):
startx = self.posx
starty = self.posy
for i in range(1,51):
display.fill_rect(self.posx,self.posy,self.size,self.size,0)
display.text(self.name,self.posx+self.size+2,self.posy,0)
self.posx = int(startx + (endx - startx) * i/50)
self.posy = int(starty + (endy - starty) * i/50)
self.update()
a = box(10,10,10,"A")
button = Pin(34,Pin.IN)
button_press = False
global interrupt_pin
def handle_interrupt (pin):
global button_press
button_press = True
global interrupt_pin
interrupt_pin = pin
button.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
instance=[]
boxcount = 0
for x in range(1500):
time.sleep(0.01)
if button_press:
boxcount +=1
print("buttonpress!")
instance.append(box(random.randint(1,128),random.randint(1,64),10,str(boxcount)))
button_press = False
a = box(10,10,10,"A")
the whole thing