#help-with-rp2040-pio

1 messages · Page 5 of 1

summer marten
#

Good morning! I'm not 100% sure if this should be in the rp2040 channel or the circuit python channel. So trying here. I've been trying to set up a UART connection. TX & RX. Transmission works fine, but I can't seem to receive anything. I've narrowed it down to the Pico. I've plugged GP0 into GP1 for this example... though what I'm trying to do is use a second device for sending, which was giving me no good results.

Here is my example code:

import board
import busio
import time

uart = busio.UART(tx=board.GP0, rx=board.GP1)

while True:
    uart.write(bytes("k", 'utf-8'))
    data = uart.read(32)  # read up to 32 bytes
    print(data)  # this is a bytearray type
    

    if data is not None:
        # convert bytearray to string
        data_string = ''.join([chr(b) for b in data])
        print(data_string, end="")

I get just a bunch of None's. I've tried with two different pico's and two different jumpers.

summer marten
subtle bane
#

You might not have good contact since you didn't solder the pins

summer marten
ripe geyser
#

Does anyone know the pin on the ItsyBitsy RP2040 that controls the power to the Neopixel? The product page mentions this but I don't see it on the Pinouts page, only the data pin is mentioned there

exotic moth
#

In CircuitPython, it's board.NEOPIXEL_POWER. At the hardware level, it's GPIO16.

ripe geyser
#

thanks! I'm using Arduino.

#

I totally forgot about checking the schematic shallafacepalm

exotic moth
cobalt inlet
#

Hi, I'm currently trying to setup my raspberry pi pico as usb rubber ducky thanks to circuitpython, adafruit hid and pico-ducky. Everything works pretty fine but I was wondering if is there any way to fix that when I plug the raspberry pi pico with a payload windows detects that is a usb device and opens the windows explorer folder of the raspberry pi pico, Is there any way to be more stealth ? ^^ thanks you

shell badge
cobalt inlet
#

thank you for the help @shell badge , but is it possible to change some hardware settings to hide or lock the raspberry pi pico (like "I'm not a usb drive don't read me") so it's done pre-plugged and not by disabling the autoplay settings? I thought that a simple solution can be closing the window immediatly by sending alf f4 inputs but it will be slower, let me know if someone has any better idea or some source about it, Thank you

shell badge
#

You would need to disable the USB MDC setting which I believe you can do in boot.py. I’m not 100% sure how to do that but I know some people here might.

cobalt inlet
#

Oh thank you so much about the informations ❤️

frank quail
cobalt inlet
#

You are gold both of you🤩, so the only way to get access to the storage is by resetting with the reset button? I can enter into a setup mode by connecting the pin 1 (GP0) to pin 3 (GND), nothing much I can do after adding the code?

frank quail
#

yeah you can add the same test in boot.py to decide to disable the USB drive or not

cobalt inlet
#

Smaart boy

#

thank you very much

frank quail
#

you'll have to have it pressed while to board boots

cobalt inlet
#

May I ask what did you use the raspberry pi pico for? I'm pretty new in this world and now i'm just playing around and trying everthing

frank quail
#

(can't change the USB after boot.py has run)

cobalt inlet
frank quail
#

I use a few different Circuitpython boards around, not the pico specifically outside of tests

cobalt inlet
#

I was trying to add the commands into the boot.py but I have only a code.py which works I guess immediatly at run, works the same I guess, Ill try

frank quail
#

boot.py is also only run on hard reset

cobalt inlet
#

Thank you very much @frank quail and @shell badge

shell badge
#

No problem

cobalt inlet
#

`import storage
import digitalio
import time
from board import *

check GP0 for setup mode

see setup mode for instructions

progStatus = False
progStatusPin = digitalio.DigitalInOut(GP0)
progStatusPin.switch_to_input(pull=digitalio.Pull.UP)
progStatus = progStatusPin.value
defaultDelay = 0
if(progStatus == True):
storage.disable_usb_drive()`

frank quail
#

ah you need CP 7 too

cobalt inlet
#

cp7 ?

frank quail
#

what does boot_out.txt say ?

cobalt inlet
#

boot.py output:
Traceback (chiamata più recente per ultima):
File "boot.py", riga 14, in <module>
AttributeError: L'oggetto 'module' non ha attributi 'disable_usb_drive'

#

Lemme translate

#

the object module doens't have attributes

frank quail
#

no but, the version above that, it's 6.3.0 right ?

cobalt inlet
#

Adafruit CircuitPython 6.3.0 on 2021-06-01; Raspberry Pi Pico with rp2040

#

yes

#

time to update?

#

xd

#

Ill install the new cp then

frank quail
cobalt inlet
#

Okay thank you, ill try

cobalt inlet
#

Everything works perfectly

shell badge
#

Good to hear

subtle bane
#

So I'm getting ~4.1V on VBUS, ~3.9V on VSYS, ~3.45-3.5V on 3V3_EN, and ~2.35-2.4V on 3V3(OUT) on my Pico... what is going on?!

#

Trying to use a temp sensor and it just isn't behaving, is it voltage related? Have it connected to VSYS tho, and it specifies 2.7-5.5V in the learn guide...

#

Nevermind, meter battery was low

shell badge
#

That’ll do it

subtle bane
#

shakes fist at meter

agile lichen
simple nexus
#

I followed the guide... and have loaded a script that uses PWMIO but I get an error... I'll post here... its like PlatformDetect is failing to work out that my Pi Pico is an RP2040.

#

Here is the error....

#

these are the libraries I have loaded on the Pico.

#

This is the code I am running a simple servo example from CircuitPython Essentials.

#

"""CircuitPython Essentials Servo standard servo example"""
import time
import board
import pwmio
from adafruit_motor import servo

pwm = pwmio.PWMOut(board.GP0, duty_cycle=2 ** 15, frequency=50)

my_servo = servo.Servo(pwm)

while True:
for angle in range(0, 180, 5): # 0 - 180 degrees, 5 degrees at a time.
my_servo.angle = angle
time.sleep(0.05)
for angle in range(180, 0, -5): # 180 - 0 degrees, 5 degrees at a time.
my_servo.angle = angle
time.sleep(0.05)

#

.... thanks... any pointers greatly appreciated.

simple nexus
#

@stone mulch was hoping you might have a tip for me on the problem above. Appreciate any time you can give to help.

#

@stone mulch I also note in your guide you mention that libraries in MPY format will not work in MicroPython. I noticed that the Adafruit CircuitPython servo.mpy library is an MPY file. Is it the format of the file that is the problem or just the file extension. Is it as easy as renaming the file with a .py extension to fix this or is the format of the MPY file fundamentally different and the reason Mircopython can not interpret it?

shell badge
#

@simple nexus don’t tag people directly to answer questions unless it’s a reply or an ongoing conversation. There are lots of people who can help on the server 🙂

simple nexus
#

@shell badge thanks for the tip... sorry new to discord, not up on the etiquette... I assumed given its was a question regarding Melissa's tutorial/guide and she is on the server it would be ok. To confirm should I post without tagging anyone... just hope someone reads it? Or is there a better way to tag folks who might be able to help... like the helpers? Sorry learning the ropes.. any direction you can give appreciated.

shell badge
#

Best thing to do is post your question and the relevant details and someone will try to help as best as possible 🙂

#

We try not to tag moderators or Adafruit peeps because usually other people in the community as capable of helping. This makes sure the moderators and Adafruit people can better respond to other moderation issues that tend to arise 🙂

simple nexus
#

Fair enough...

storm heath
#

@simple nexus the .mpy files are pre-compiled and the formats for Circuitpython and Micropyhton are not compatible.

simple nexus
#

@storm heath cheers, thanks for that super helpful.

stone mulch
#

@simple nexus I don’t think pwmio was ever implemented via Blinka. You could open an issue on the Blinka repo or possibly try and add it yourself. As for libraries, I just use the .py files, though MP may have a tool for compressing them. I know the CP one is called mpycross and it might be the same name, but available through MP.

simple nexus
#

@stone mulch Thank you very much... I will take a swing at it. Thank you again and thanks for putting together the tutorial!

frosty stump
#

Hello! I dont know if this should go here or in another channel. I am playing around with the 19th box and customizing the macropad hotkeys projects. I have two questions

  1. Any way to hide the CIRCUITPY drive? I just dont like it there, and if not possible is it possible to leave it read only so that it doesnt reboot anytime that I accidentally click on it.
  2. Any way to setup a button to put the macropad on standby and turn all lights and led off?
    Thanks!
frank quail
#

2 - yes, you need to change the hotkeys code for that, the simplest being to hardcode a key, like inserting something like this to hardcode the knob to do that (in if pressed for example)

if key_number == 12:
    macropad.pixels.fill(0)
    macropad.pixels.show()
frosty stump
#

Awesome! Thank you @frank quail !

frank quail
plucky goblet
#

I've looked everywhere but have been unable to locate how to use the NeoPixel on the Itsy Bitsy RP2040 in MicroPython. CircuitPython, yes, but no MicroPython. I'm able to rshell onto the board, blink the red LED, and everything is working, but I can't find either the neopixel library or an example in MicroPython. Thanks for any help!

frank quail
#

I thought the neopixel library was built into microython ?

small meteor
#

ws82 something

#

pico-sdk has a board include to identify the pin

#

(one additional pin to power the npx)

#

Just about every last port for RP2040 leverages pico-sdk

frank quail
#

ah the neopixel library might not be included on the rp2040 build ?

#

and true, there is a neopixel power pin to set too, GPIO16

plucky goblet
#

I thought that was CircuitPython. I flashed mine with rp2-pico-20210902-v1.17.uf2

frank quail
frank quail
#

(obviously it doesn't mention the rp2040, but I extrapolate)

plucky goblet
#

And then I just need to make sure I'm using the correct pin for the Itsy Bitsy it seems...

small meteor
#

Power 16, NPX pin 17

plucky goblet
#

Yes, understood, thanks!

#

Okay, so I've copied neopixel.mpy to /pyboard/ via rshell, and added import neopixel to my existing blink program without attempting to do anything else. Exiting from rshell and resetting the board apparently this import breaks my blink program, so it's failing somehow. This without any attempt at creating a NeoPixel, just the import itself. I tried adding __init__.py to the directory (a bad guess) but that made no difference.

#

My /pyboard/ directory contains main.py and neopixel.mpy. My code is:

from machine import Pin, Timer
#import neopixel
_led = Pin(11, Pin.OUT)
def toggle_led():
    _led.value(not _led.value())
_timer = Timer(freq=2, mode=Timer.PERIODIC, callback=lambda n: toggle_led())

If I uncomment the second line it will fail.

#

I also tried:

from neopixel import NeoPixel

but that made no difference.

small meteor
#

I use tab-completion a lot ;)

plucky goblet
#

bed time here: 2:36am. The Itsy Bitsy defeated me. 😝

small meteor
#

next time gimmem the gom jabbar

plucky goblet
#

Ah, you can't write "maso chist" here.

#

So, I'm a maso chist that now needs to write a long message over again...

#

I tried both the blaz-r "Neopixel" and the official MicroPython "NeoPixel" versions. The former at least compiles in the REPL and throws no exceptions but nothing happens, and yes, I'm setting pin 16 high. When I try importing the MP version it errors out with "ImportError: can't import name bitstream" which is strange considering that bitstream is machine.bitstream. Is that not implemented on an RP2040? So I'm stumped.

I am a bit surprised that Adafruit have released a board advertised with a NeoPixel on it but provided no working example code for that NeoPixel. I'm not a Python professional but I'm not a noob either, and I've spent several hours trying to fire up the NeoPixel on my Itsy Bitsy RP2040, with no luck. 😑

distant spade
#

@plucky goblet Adafruit doesn't support MicroPython on our boards. It's been added by the MicroPython community (mcauser) It should work in CircuitPython without issue

plucky goblet
# distant spade <@!828135237744984114> Adafruit doesn't support MicroPython on our boards. It's ...

I was rather hoping nobody would suggest CircuitPython because I'm starting to see the pattern now. I understand Adafruit are promoting CircuitPython, but at this point it is clearly at the expense of MicroPython. I can't use CircuitPython for my application. I like the ItsyBitsy RP2040 (quite a lot) but if there's no support for MicroPython I guess I'll have to use a different board then, and stop considering it for future applications (which all use MicroPython). And yes, I do think Adafruit is making a big mistake here, but I don't want to cause an argument over it as I can see the company is invested in CircuitPython. It has created a divided and confused community. I'll just choose a different board that supports MicroPython.

distant spade
#

Adafruit simply cannot support all software for all uses on its boards. I understand it's frustrating for folks when we don't have software support but software is hard and takes time. We have to choose where to put our energy.

plucky goblet
#

Yes, understood. I'm simply talking about the NeoPixel on the Itsy Bitsy RP2040 as an example file in MicroPython. Those example files (like 'blink') are very useful in that they demonstrate how to get up and running for beginners, but also how to install and use support libraries. I've spent several hours trying to use the NeoPixel and I can now give up and just find a different board. If I'm typical (and I'm not a Python noob), that doesn't sound like a very good outcome for anyone.

distant spade
#

Did you ask on the micropython forum?

plucky goblet
#

I'd moved over from the Itsy Bitsy M4 Express as I'd made up a bespoke socket for it on my robot, and just plugged in the Itsy Bitsy RP2040 and thought I'd have a MicroPython microcontroller. As the ESP32 won't work for me either (it can't implement the I2C slave protocol) I'll likely move over to the PyBoard D-series, which is native MicroPython at 216Mhz. Expensive but at least fully-supported by the community. But I'll have to dump my Itsy Bitsy socket and start over.

distant spade
#

why do you need micropython?

plucky goblet
distant spade
#

it looks like neopixel support in 1.17 just changed

plucky goblet
plucky goblet
distant spade
#

ya, definitely try 1.16

plucky goblet
#

I keep copies of all the older ones. Okay, thanks, will give that a try.

#

...with both libraries. If I can use the official NeoPixel rather than the blaz-r Neopixel that would be good. I'd like anyone prefer not to rely on single-developer libraries if possible (though admittedly I can hardly complain about pigpio).

plucky goblet
plucky goblet
#

Success! 😃 using the blaz-r Neopixel library. You download the neopixel.py library and put it at /pyboard/neopixel.py then use this for main.py:

# Uses the Neopixel library downloadable from:
#
#    https://github.com/blaz-r/pi_pico_neopixel
#

from machine import Pin, Timer
from neopixel import Neopixel
import utime

RED    = (255, 0,    0)
ORANGE = (255, 165,  0)
YELLOW = (255, 150,  0)
GREEN  = (0,   255,  0)
BLUE   = (0,   0,  255)
INDIGO = (75,  0,  130)
VIOLET = (138, 43, 226)
COLORS = [ RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET ]

# red LED
_led = Pin(11, Pin.OUT)

# NeoPixel power pin 16
p16 = Pin(16, Pin.OUT)
p16.value(1)
# NeoPixel pin 17
np17 = Neopixel(num_leds=10, state_machine=0, pin=17, mode="RGB")
np17.brightness(108)

# ................................................
def toggle_led():
    _led.value(not _led.value())

_timer = Timer(freq=3, mode=Timer.PERIODIC, callback=lambda n: toggle_led())

# cycle NeoPixel through colors ..................
while True:
    for i in range(len(COLORS)):
        np17.set_pixel(0, COLORS[i])
        np17.show()
        utime.sleep(1.0)
#

This blinks the red LED using a hardware Timer and unicorns the NeoPixel.

#

With an alternate unicorn implementation:

def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if pos < 0 or pos > 255:
        r = g = b = 0
    elif pos < 85:
        r = int(pos * 3)
        g = int(255 - pos * 3)
        b = 0
    elif pos < 170:
        pos -= 85
        r = int(255 - pos * 3)
        g = 0
        b = int(pos * 3)
    else:
        pos -= 170
        r = 0
        g = int(pos * 3)
        b = int(255 - pos * 3)
    return (r, g, b)

while True:
    for i in range(255):
        np17.set_pixel(0, wheel(i))
        np17.show()
        utime.sleep(0.01)
tacit arch
#

Is it possible to boot two RP2040s with a single flash chip?

#

The RP2040 doesn't have enough analog pins for me (I need six so I can get 96 inputs with multiplexers) so I was thinking I'd just use two... But having to flash twice to update the firmware would be annoying so I'm curious if i could just flash one SPI flash chip and have both RP2040s boot off of it

shell badge
#

Could use an ADC, or analog IO expander

tacit arch
#

(using 74HC4067 analog multiplexers)

#

I've never used an I2C ADC chip before but I suppose I could use those... If they're actually available and don't cost a fortune

#

All the ADCs I've ever looked at were much more expensive than the RP2040 but it's been a while

#

I guess the other question I have is: If I have dual RP2040s on a single board how do I flash two SPI flash chips at once?

shell badge
#

USB hub interface controller

tacit arch
#

Yeah those are impossible to get right now

#

I've been waiting for fe1.1 to be back in stock for months and months

shell badge
#

There ya go

#

500+ in stock and <$4

#

100+ of those

#

I personally like the TI controllers

shell badge
plucky goblet
#

FYI, as an update, I've added my Itsy Bitsy RP2040 unicorn-blink NeoPixel implementation to my github repo. It's perhaps got more than most people need (e.g., a 20Hz hardware Timer, which I use as a system clock on my robot) but likely is a good start for anyone trying to either blink the red LED or display unicorns on their Itsy Bitsy's RP2040 NeoPixel. The file is called main_ext_clock_rp2040.py, but should be copied to /pyboard/main.py along with the neopixel.py file whose source is linked in the comments.
https://github.com/ifurusato/kros-core/blob/main/main_ext_clock_rp2040.py

GitHub

KROS Core provides the core functionality of a K-Series Robot Operating System (KROS), a Raspberry Pi based robot written in Python 3. - kros-core/main_ext_clock_rp2040.py at main · ifurusato/kros-...

small meteor
#

good on ya for publishing findings. ;)

#

@tacit arch Chip Select is the boot mechanism for RP2040 - the pushbutton interrupts it or grounds it or brings it to Vcc, which forces the on-chip (RP2040) boot stuff to 'look elsewhere for joy' iirc.

#

My guess is you'd then recode the pico-sdk to become 'chip select selective' (lol) to work with more than one QSPI flashROM chip on the bus for that.

#

Not sure how deep the RP2040 hardware is married to the xternal flashROM.

#

flashing the flashROM uses the .UF2 strategy.

#

Might be some sort of JTAG thing somewhere; not sure how that works.

#

You can definitely upload code without 'seriously' writing to flash - it'll run in SRAM.

#

To the extent that you can either cycle power to reboot from the previous firmware image stored on flashROM, or examine the existing flashROM and see it's all still there, when you uploaded firmware to SRAM-only.

#

So the SRAM based uploads do not damage the on-flash storage of your (longer term) program.

#

This mechanism can be used to do some kinds of testing of your on-flash stored program, without booting 'it'.

#

I used this when porting Dr. Brad Rodriguez' CamelForth to RP2040.

#

(had a stable version of CamelForth in flash, testing an unstable one in SRAM-only) (they were different enough for this test to be very useful for debugging experimental code enhancements).

#

In one instance, the stable version continued to boot regularly, while the unstable version wouldn't even boot, if written to flashROM. ;)

#

Also I had a forth 'word' accessible in the flashROM version to initiate mounting of the 'drive' for .UF2 upload - nice to have on boards without the pushbutton easily activated (or having to physically unplug USB to reflash).

wraith heart
#

With a hardware debugger many things are possible

#

STM32s would be so much harder without STLinks.

tacit arch
#

@small meteor That's super useful info! Thanks! Here's another question: Can you copy what's in SRAM to flash to make it the new boot flash?

small meteor
#

;)

#

Um I have not tried that! I think there's a material difference between the in-SRAM image 0x20000000 and the flashROM image 0x10000000 but it's been several weeks since I've thought about it (at all).

#

The lowest bytes is where I'd expect the most change.

#

I seem to remember there were unexpected differences.

#

I briefly understood the boot process, some .. but it's been a while.

#

(generally I rethink such things as-needed)

spring iron
#

Can I send messages over the USB to a python program from my pi pico?

#

It's currently reading temperature data

frank quail
spring iron
#

Yup exactly what I want to do

#

Do I have to set it up or does it always act as one?

frank quail
#

what are you running on it ?

spring iron
#

Circuitpython

frank quail
spring iron
#

Well

#

That was easier than expected

frank quail
#

it's pretty easy yeah

spring iron
#

I just expected that I have to tell Pico to enable serial and baud rate and all that stuff

frank quail
#

at the core you only need "print" 😉

spring iron
#

Well, now to write some code that properly connects to it. Thanks Neradoc

frank quail
#

it's communication in the other direction that takes a tiny bit more to do in a non-blocking way, and finding the board automatically, and enabling the serial data channel to make it easier to debug with the REPL can be nice additions that are covered in my examples

spring iron
#

And then to check if my ovens temperature is still accurate

#

Yeah I had a quick look through and it seems the proper way of doing it yeah

wraith storm
#

Is serial communication pretty robust? I occasionally drop characters (SAMD21) but not sure if I'm doing it wrong, or this is common

waxen aurora
wraith storm
#

yeah, it's a pretty rare occurrence, like 0.01% or so, so it's pretty hard to track down and troubleshoot

eternal grove
#

Could be a buffer overrun or interrupt conflict.

wraith heart
#

Or a seriously marginal oscillator.

wide musk
#

I am able to run circuitpython on my Pico, but am not able to get started with micropython. Is this the right channel to ask help questions related to micropython?

#

When I copied the circuit python .uf2 file, immediately, I was able to see a CIRCUITPY drive on my computer. When I copied the PICO micropytohn .uf2 file, I do not see any directory on my drive. Is this an expected behavior for micro python?

vivid pewter
#

the howtos seem to suggest it just works after the micropython upload, is the mp uf2 file undamaged/up to date?

#

(we don't seem to have a micropython channel, and technically this channel is just for the programmable I/O hardware of the rp2040, but it is a good place for rpi2040 conversation, I'll try to cry out if the moderation ninjas disappear me for saying this)

wide musk
#

Thanks @vivid pewter I tried with 1.16 and 1.17 from https://micropython.org/download/rp2-pico/ and same issue. Subsequently, when I tried circuitpython.uf2, it is working

vivid pewter
#

I have four pi picos lying around, and I have yet to plug one in (despite how clearly awesome they are)
I'll have to try someday soon now (in part because I want to taste the Viper)

#

no chance the micropython uploads weren't fully uploaded somehow? (didn't "eject" the drive, etc?)

wide musk
#

Can you do micropython development on Pico from Windows? or is it that you need a Mac? Wondering whether that may be the issue. circuit python development is working from a Windows machine @vivid pewter

vivid pewter
#

I expect it'd be the same as circuit python, but, I'm biased against windows, I've done little development there

plucky goblet
#

I wouldn't recommend using any of the "unstable" downloads, version 1.14 to 1.17 are fine.

wide musk
#

I tried both with 1.17 and 1.16

wraith heart
#

Micropython doesn't expose a mass storage device like circuitpython.

#

You have to transfer files to the device with a client program like ampy or pyremote, or an IDE that has such built-in like Thonny

vivid pewter
wraith heart
#

That is a bit outdated, as it was written before pyremote

vivid pewter
#

huh, found a micropython interpreter for my not-micro machine

wide musk
plucky goblet
wide musk
#

Yes. Thanks very much to @plucky goblet to walk me through the whole troubleshooting step by step 🙏

plucky goblet
#

FYI, for those interested, we used rshell, which I'm happy to say works very well as a basic shell environment for MicroPython (especially since I'm a native vi/vim user and "edit" starts up a vim session).

wraith storm
#

anyone know if PIO expressions are evaluated once at compile time, or can you use them to do active division inside the statemachine?

distant spade
#

CP doesn't allow you to change them as the program runs

#

under the hood you could

#

you can also write a program that loads in a program and executes it

wraith storm
#

yeah, I want to do active division inside of the PIO program, so I might be out of luck

vivid pewter
#

I don't think PIO does much more than count and move memory

plucky goblet
vivid pewter
#

I'm not downplaying the PIOs awesomeness, it just isn't a TPU :-)

vivid pewter
#

now pondering using PIO to run 6 separate parallel IR transmitter outputs

plucky goblet
#

I've just today received and assembled my Macropad. Verra nice unicorns! 🌈 🦄 😀

Does anyone know of a library to connect the Macropad to a Raspberry Pi (or other Linux computer) and both send data to and from the Macropad, i.e., keypad info back to a Pi or from the Pi to the OLED or to set the color of the NeoPixels? I've so far only seen code on how to use it as a standalone device or use the serial port. Obviously using it as a UI for another computer would be (IMO) kinda its main purpose, unless it's just meant to be an expensive gadget. I'd like to use mine as a UI on a robot but so far haven't figured out how. I'm already using the UART on my Pi so hopefully something else like I2C is also an option here...

I've just been looking into HID, but that doesn't seem to be the whole picture either, hence my question — I'm kinda assuming this is all available somewhere and I just can't find it..

vivid pewter
#

I think I've seen at least one tutorial/project where the computer backfeeds data to the macropad
its an almost obnoxiously capable device, very little has been done to hold it back, looks like the design intent was "follow your dreams!"

#

one project uses MIDI protocol to sneak data into it

#

serial via USB should be doable

#

lazy-mode, it should be possible to puppet the keypad automatically like I normally do manually, by throwing python commands into it's REPL

#

it is ambiguous to me if there is a back channel through mouse and keyboard emulation as well

#

there should be a "STEMMA QT" connector, which is adafruitese for I2C

plucky goblet
# vivid pewter there should be a "STEMMA QT" connector, which is adafruitese for I2C

Well, I'm most interested in I2C but that would assume that the Macropad is I2C slave capable, but I've not seen that done anywhere yet. MIDI won't work for me, and I don't know what HID is. UART would normally work except the only available UART on my Pi is already in use. So I would be keen to know how the I2C/STEMMA QT connector could send and receive data to/front a host computer...

plucky goblet
#

Does anyone know of an example of using the NeoPixel on the QT Py RP2040? The Adafruit web pages are for CircuitPython (e.g., "board.NEOPIXEL") but I'm using it with MicroPython, so I need the Pin number for the device, e.g.:

from machine import Pin
from neopixel import Neopixel
neo = Neopixel(num_leds=1, state_machine=0, pin=17, mode="RGB")
neo.brightness(108)

Either an example file or just the pin number I'd use in MicroPython would be great. I've used the ItsyBitsy RP2040 successfully, where it requires setting Pin 16 as the power pin. I'm assuming due to the much smaller number of pins on the QT Py that the NeoPixel is always enabled and doesn't require this (?). Thank you! 😀

frank quail
#

the power pin is for reducing power draw, it's likely to exist on every future Adafruit board that could be used on battery (unlike the macropad which is more targeted to be used plugged on USB).
If the pin is not in the board's guide pinout page, rather than look at the schematics I tend to use circuitpython's pins.c as reference:
https://github.com/adafruit/circuitpython/blob/main/ports/raspberrypi/boards/adafruit_qtpy_rp2040/pins.c
so in this case, even if you don't know what those macros do, you can decipher:

    { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO12) },
    { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO11) },
plucky goblet
#

Ha! 😆 I was just coming back from digging around, was going to paste this:

    { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO12) },
    { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO11) },
frank quail
#

so, 12 and 11

plucky goblet
#

yeah, I dug around in the C code for the CircuitPython port for the board.

#

Funny thing is, I'm looking at the Adafruit docs but I can't figure out which is pin 11 and 12... hmm.

frank quail
#

that's the pins on the rp2040

plucky goblet
#

SDA1 and SCL1?

#

Understood, it's not clear where they end up on the QT Py.

frank quail
#

oh on the on-board neopixel

plucky goblet
#

Ah, doh.

#

Yeah, not physical pins.

#

So something like this:

# power pin 11
power_pin = Pin(11, Pin.OUT)
power_pin.value(1)
# NeoPixel pin 12
neopix = Neopixel(num_leds=1, state_machine=0, pin=12, mode="RGB")
neopix.brightness(108)
small meteor
#

The schematic for QTPY RP2040 seems clear.

small meteor
#

14 and 15 are package pins for the RP2040 chip itself.

plucky goblet
#

I hadn't thought to look for the schematic, which I've now downloaded, so GPIO 11 and 12, package pin 14 and 15. Yes, thanks. 🙏

small meteor
#

I think you'll find the Adafruit schematic for anything they make is a primary reference for pinouts and such. ;)

plucky goblet
#

Yes, agreed. I've had an Itsy Bitsy RP2040 and a TinyPICO (on a robot) but thought to swap out the TinyPICO today when the QT Py showed up in the post. I'm just using it as an independent 20Hz external clock for a Pi so the smallest board is the best.

#

Then I'll have two RP2040s so the MicroPython code for both will be mostly the same.

small meteor
#

As far as I know, the RP2040 chip is of a single variety so it should be programmed nearly the same in any target implementation. Have not looked at external crystal frequencies so I don't know if that's in play or not. ;)

plucky goblet
small meteor
#

Package pins 20 and 21 - the 12 MHz crystal - that could vary in some other target.
QSPI flashROM chip used is pretty well guaranteed to vary, here and there.

shell badge
#

12MHz crystal shouldn’t vary except load capacitance and strength limiting resistor for the rp2040

plucky goblet
#

Perhaps you didn't catch the frequency: 20Hz. My clock requirements are so slow that any microcontroller can likely handle it, and slight variances aren't going to have a huge impact on the robot (by design, the clock speed just needs to be mostly consistent). But running that clock in Python3 on a non-RTOS Linux had huge variances depending on what the Pi and Python happened to be doing. The easiest thing was some kind of external clock. This spits out numbers around 49.8 - 50.5ms reliably no matter what is happening on the Pi.

small meteor
#

;)

#

I have no idea how you stabilize such a clock.

shell badge
#

RTC?

small meteor
#

My cave-man level wild guess is a fully interrupt driven firmware. ;)

shell badge
#

Here’s a thought, if you maintain an 8 bit wide array to store the last 8 outputs from your “clock” and the. Average them?

#

Your average would probably be relatively accurate to 50ms

small meteor
#

They do have binary crystal frequencies. ;)

#

32768 kHz iirc

shell badge
plucky goblet
# shell badge RTC?

No, I'd thought about that too but they're entirely useless for anything less than one second. An RTC's design is for accuracy over long periods.

If I could suggest any product to Lady Ada (though I wouldn't ping her), it would be an I2C board that provided a single function: a nanosecond clock. It wouldn't have to be accurate like an RTC (like, over a day or a month), but a very nice consistent nanosecond counter from the epoch would be very valuable.

plucky goblet
eternal grove
#

Given how slow I2C is, a nanosecond clock seems somewhat silly.

shell badge
#

That RTC has usec accuracy

plucky goblet
plucky goblet
shell badge
#

Standard mode has frequencies from 0-100kHz

plucky goblet
#

But that's accuracy. Most of the RTCs I've seen are accurate but you can't get a number out of them with a finer resolution than one second.

#

So what I'm wanting is something less accurate but with a much higher resolution.

#

...like microseconds or nanoseconds.

#

Basically, I can use a microsecond-accurate tick (nanosecond would be overkill) in a PID controller (in MicroPython) and self-adjust (as is the nature of PID) based on the tick count. But if my tick count is millisecond-resolution I get noticeable swings.

#

And I'd use a crystal if I could find some reasonable way of modulo'ing it down to 20Hz or 25Hz, but that's crazy talk so the nano- or microsecond tick counter (like you get in Java on a normal Intel box) would be a suitable way of solving this.

shell badge
#

This might be useful

#

It’s more looking at the C++ side though

plucky goblet
#

Yes, I'm just reading that now. Certainly looks like a possibility. Makes my little MicroPython "system clock" look pretty weak by comparison.

shell badge
#

Not sure how you would translate that to MicroPython

small meteor
#

32.768 kHz which is roughly 32 kHz ;) Not 32,768 kHz (32.7 MHz)

plucky goblet
#

I think I'd have to write the PIO myself. Which is in some form of assembly or something (never investigated that yet).

shell badge
#

PIO doesn’t seem very difficult

plucky goblet
shell badge
#

It’s pretty close to assembly with some C like structs

plucky goblet
#

If all I'm trying to do is write an oscillator with a fixed frequency that doesn't look to be too difficult. Thanks for the reference and the help. It's almost 2am here so I suppose I should call it a night. 🙏

small meteor
#

Ham receivers had 100 kHz oscillators designed to emit harmonics at 100 kHz intervals - very wide range. ;)

#

That's how you calibrated your receiver to make sure you didn't go out of band.

plucky goblet
small meteor
#

Nah it was all analog iirc. They just used an oscillator design that did it inherently. The xtal was a really tall can.

#

Like 1.25 inches with a normal crystal footprint.

eternal grove
#

However, it is simple to make dividers (even synchronous dividers) from TTL/CMOS chips.

small meteor
#

It was a standard newcomer first-project to make one.

plucky goblet
#

An all-software solution like the PIO sounds good. But I still like the idea of a board with a nano- or micro-second from-the-epoch counter on it.

small meteor
#

The period literature also recommended harvesting the 'color burst' oscillator crystal from a TV set.

eternal grove
#

If you don't need from the epoch, but just a counter (which should be suitable for PID), it's a lot easier.

plucky goblet
plucky goblet
eternal grove
#

If you want plenty of accuracy, used rubidium frequency standards flooded the surplus market due to mass cell tower upgrades. They give a very accurate 10MHz output. There are also GPS disciplined clocks that offer nanosecond accuracy, but that's starting to get complicated.

plucky goblet
#

Where would I find one of these rubidium frequency standards? (sounds like the name of a math rock band)

eternal grove
plucky goblet
#

BTW, this is for a chicken-sized robot...

eternal grove
#

These are a little larger than a deck of cards, but do eat a fair amount of power, and are likely extreme overkill for your use case.

plucky goblet
#

Extreme overkill lol but cool factor 1000%

#

My little chicken-size robot lugging around a big metal box. 😝

eternal grove
#

I totally get that.

plucky goblet
#

I didn't know such things existed (though of course they do) but here in NZ it'd be pretty expensive (NZ$320, which feels here like US$320).

eternal grove
#

I suspect the DS3231 that skerr mentioned would be an appropriate choice. Other possibilities include that plus a PLL to get an accurate nanosecond clock, or a higher frequency thermally compensated crystal oscillator.

plucky goblet
#

Yes, but while accurate it's still a resolution question. I was pretty bummed when I found out that the RTCs have a 1 second accuracy. I'd have to dig into that spec sheet but my guess is that it's the same in that regard.

#

I would think microsecond accuracy would be fine.

#

And thermal compensation wouldn't even be that necessary. If I can get variance on a 20Hz clock over 1 second down to less than 1% I'd be fine.

#

I'm currently hovering around 1-2%.

eternal grove
#

An ordinary crystal oscillator plus divider chain might be suitable then.

plucky goblet
#

Yeah, I'm thinking that might be. It was the additional circuitry (and bother) of building out the dividers that turned me off of that approach.

#

I currently like the PIO idea the most, but I'd have to learn a new language (horrors!)

eternal grove
#

It would be very handy if there were a chip that contained a synchronous counter with a lot of bits plus an I2C or SPI interface to read its value

plucky goblet
#

I'm guessing somebody has already written an oscillator for the PIO though so I might not have to start from scratch.

plucky goblet
eternal grove
#

It would be pretty easy to implement with an FPGA

plucky goblet
#

Put it this way: I would buy one. A programmable frequency.

#

Like one of those Pimoroni Breakout Garden boards. An I2C device you could poll for a value. Relative to the moment the board starts up would be fine, bonus points for January 1, 1970.

eternal grove
plucky goblet
#

Wow, yes. I'm not in a position to create a carrier board for it, but I see there's a DIL package too.

#

28 pins!

#

Put one of them on a board with a crystal and some kind of controller with a Python support library that'd be a cool product.

#

Anyhoo, I very much do appreciate the help but I need to get to bed as I have to get up in about five hours, so ciao, thanks!

plucky goblet
# plucky goblet So something like this: ```python # power pin 11 power_pin = Pin(11, Pin.OUT) po...

I just want to report that the MicroPython code I posted earlier (setting power pin 11 high, NeoPixel on pin 12) works successfully with the NeoPixel library found at: https://github.com/blaz-r/pi_pico_neopixel
So here's a working blink example for /pyboard/main.py:

from machine import Pin
from neopixel import Neopixel
import utime

BLACK    = ( 0, 0,  0)
SKY_BLUE = (40, 0, 72)

# power pin 11
power_pin = Pin(11, Pin.OUT)
power_pin.value(1)
# NeoPixel pin 12
neopix = Neopixel(num_leds=1, state_machine=0, pin=12, mode="RGB")
neopix.brightness(108)

while True:
    neopix.set_pixel(0, SKY_BLUE)
    neopix.show()
    utime.sleep(0.01)
    neopix.set_pixel(0, BLACK)
    neopix.show()
    utime.sleep(1.0)

I've got a blinkin' light. 😁

GitHub

Pi Pico library for NeoPixel led-strip written in MicroPython. Works with ws2812b (RGB) and sk6812 (RGBW). - GitHub - blaz-r/pi_pico_neopixel: Pi Pico library for NeoPixel led-strip written in Micr...

plucky goblet
#

Though I just noticed that the argument for NeoPixel mode for some reason isn't (in practice) "RGB" but actually "GRB".

river maple
#

GRB is the on wire byte order for some reason

hearty citrus
#

whats different between the rp2040 and other boards

glass star
#

rp2040 is the chip, pico, feather 2040, itsybitsy 2040 etc are the dev boards

#

https://github.com/picoruby/prk_firmware <- me being a ruby person, this is a pretty interesting project. Ruby on micro controllers is no where near capabilities of circuit/micro python. This looks more like how one might set up a small lua scripting interface for a video game. But still, for me, intriguing 🙂

GitHub

A keyboard firmware platform in PicoRuby. Contribute to picoruby/prk_firmware development by creating an account on GitHub.

hearty citrus
#

Thx!

solar saddle
#

not sure if this is the right place but I got a macro pad today and tried to set it up by myself(no code experience). I loaded circuitpython onto the macropad and now all it says is code done running and none of the keys do anything.

vivid pewter
solar saddle
#

I downloaded this library and dragged it into the device and nothing happens. Do I need to put it in a specific place or just onto the device? I have little experience sorry.

subtle bane
#

Did you copy the example code into code.py?

solar saddle
subtle bane
#

Ah, that's why. You'll need to create a code.py on the CircuitPython drive and put the demo code into it

solar saddle
#

Should I download the project code file from that link and drag all the files into my device? Or just make a code.py file? Thought this would be a fun learning experience im just so lost lol.

subtle bane
#

Either one works, you'll end up with an identical code.py either way

#

Personally I prefer to make the file and paste in the code

solar saddle
#

Okay but then will I need a lib folder as well? Or all macro codes go into the code.py file?

gusty juniper
#

The lib folder is for the libraries that the macropad code gets its base functions from. Your macros will go into a separate macros folder you'll have to make.

subtle bane
hollow mantle