Go to advanced search

by horuable
Wed Aug 04, 2021 11:05 am
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Very neat solution. I think it can still be done with 2 cycles per loop by changing the low counting loop to:

Code: Select all

  label("lowloop")
  jmp(pin, "done")	# 1
  jmp(x_dec, "lowloop")	# 2
  label("done")
by horuable
Tue Aug 03, 2021 7:10 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

I find that measuring the time between the same-type edges using PIO is surprisingly hard. I can think of two solutions, both using a second, intermediate, State Machine: 1. One SM reads the input signal and outputs a high level between two rising edges on another pin (I called it GATE_PIN). This ne...
by horuable
Sun Aug 01, 2021 8:05 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Ok, somehow I didn't think about doing it that way. In this case, it's definitely the way to go. And yeah, the naming is less than intuitive... I thought about counting every revolution because it shouldn't be too hard to achieve and I think having the most up-to-date reading is never a bad idea, an...
by horuable
Sun Aug 01, 2021 5:45 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Disclaimer: Writing this post took me waayyyy longer than it should and hippy was first, but here it goes... Unfit in the sense that it often doesn't produce the frequency closest it could to what was asked for [...] In that case, I totally agree. I've noticed that before and it seemed extremely wei...
by horuable
Thu Jul 29, 2021 5:45 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

I'm not sure what you mean. Unfit for what purpose? Changing PWM frequency? I'm afraid it's the only way available. Showing how the module works? PWM is the simplest way to generate a signal with a known frequency, even if it's not perfect.
by horuable
Thu Jul 29, 2021 3:08 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Due to how PWM works the generated frequency is sometimes slightly different than what is entered in pwm.freq() call. The result that you see is the actual, measured frequency that is really generated by the PWM (I've checked it with an oscilloscope). The single Hz differences are due to how this me...
by horuable
Wed Jul 28, 2021 9:53 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Yup, every module has to be present on Pico to be used in programs. I have no idea if Thonny can upload any modules to Pico by itself, I've never tried to do that. The modules you mentioned are not really a part of Thonny libraries, but they're baked into MicroPython firmware to be always available ...
by horuable
Wed Jul 28, 2021 4:38 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

The simplest way to get a module on the Pico using Thonny is to create a new file, copy the contents of PWMCounter.py (using Raw mode for best results - can be changed at the top right of code window) from GitHub, paste, and save it to Pico as PWMCounter.py (who would've guessed, right? :D) Then to ...
by horuable
Mon Jul 26, 2021 1:06 pm
Forum: MicroPython
Topic: Speed measurement on a Triton router
Replies: 34
Views: 781

Re: Speed measurement on a Triton router

Honestly, I wouldn't use ticks_us() for this, but rather take advantage of hardware present on RP2040, specifically counter capabilities of PWM blocks, or even PIO if PWM would be insufficient. Take a look at a module I've made that simplifies using PWM as a counter: https://github.com/phoreglad/pic...
by horuable
Mon Jul 26, 2021 11:55 am
Forum: General
Topic: Drive a single APA102 on a custom RP2040 board, Windows Python luddite!
Replies: 12
Views: 367

Re: Drive a single APA102 on a custom RP2040 board, Windows Python luddite!

This error comes from the library trying to call SPI.init() method with arguments that the Pico port isn't programmed to take, namely miso and mosi. I think SPIDotStar class from the same library would be better, because it takes an SPI object supplied by the user. Try running a slightly modified ex...
by horuable
Fri Jul 23, 2021 12:03 pm
Forum: General
Topic: Bit Bang 4 ws2812 strips
Replies: 8
Views: 373

Re: Bit Bang 4 ws2812 strips

You need to be a bit more specific. What is this "demo ws2812_leds"? Can you post the code or link to it? What language do you use, MicroPython or C/C++? In general, to run 4 separate strips you'd have to initialise 4 StateMachines using different pins and then send data to a specific SM t...
by horuable
Fri Jul 23, 2021 11:13 am
Forum: MicroPython
Topic: MP UART + PIO state machine on same pins
Replies: 8
Views: 316

Re: MP UART + PIO state machine on same pins

It appears that defining a PIN for use by a UART and defining the pin as a set for a state machine is problematic, shouldn't this be doable though? Unfortunately not, UART and PIO are completely different peripherals and cannot be used to drive GPIO at the same time. And please use code tags for be...
by horuable
Thu Jul 22, 2021 3:44 pm
Forum: MicroPython
Topic: Storing a range of results
Replies: 6
Views: 266

Re: Storing a range of results

May I ask why you need to store index along the entries? It seems kinda unnecessary, since lists already index elements by themselves. If it's because you want to add elements out of order then maybe dictionary would fit better here?
by horuable
Wed Jul 21, 2021 8:36 pm
Forum: MicroPython
Topic: Cycling up and down in a range
Replies: 18
Views: 529

Re: Cycling up and down in a range

I managed to get 'myNumber.value()' down to 'myNumber()' but haven't figured out how to make that a really desirable 'myNumber'. If anyone does I'd love to know how. AFAIK it's not possible in Python. Since myNumber is effectively a function it must be called with (). If I can suggest something, I'...
by horuable
Tue Jul 20, 2021 6:35 pm
Forum: MicroPython
Topic: Help connecting SPI ST7789 lcd
Replies: 45
Views: 1239

Re: Help connecting SPI ST7789 lcd

No need to reinvent the wheel. Exactly why I did what I did. Creating this "driver" took me probably like half an hour and it allowed me to use existing and documented methods. It's also similar to how the SSD1306 OLED driver from MP repo is done, so I figured it's the right way to do it....
by horuable
Sat Jul 17, 2021 9:49 pm
Forum: MicroPython
Topic: Trivial code sometimes takes 5ms and interrupts are missed
Replies: 14
Views: 605

Re: Trivial code sometimes takes 5ms and interrupts are missed

Pretty sure it's due to floating point math and garbage collection. See this post: https://www.raspberrypi.org/forums/viewtopic.php?f=146&t=308269&start=50#p1849955 , specifically the conclusion: That has to be something MicoPython is doing itself, handling an interrupt, or clock, garbage co...
by horuable
Sat Jul 17, 2021 2:46 pm
Forum: MicroPython
Topic: Help connecting SPI ST7789 lcd
Replies: 45
Views: 1239

Re: Help connecting SPI ST7789 lcd

One thing I've noticed about some st7789 modules out there is that they use polarity=1 for screens without CS, so maybe try that. You could also try connecting CS to Pico and actually use it, just to see if it changes anything. Maybe try adding a little delay after reset to make sure it had enough t...
by horuable
Sat Jul 17, 2021 10:58 am
Forum: MicroPython
Topic: Help connecting SPI ST7789 lcd
Replies: 45
Views: 1239

Re: Help connecting SPI ST7789 lcd

You could try something I threw together some time ago, it's not the best code, but worked well for me. It's based on MP framebuf, so should support all standard drawing commands. It's very basic, anything like rotation must be done by changing register values rather than a simple function, but I sh...
by horuable
Sat Jul 17, 2021 8:56 am
Forum: MicroPython
Topic: Help connecting SPI ST7789 lcd
Replies: 45
Views: 1239

Re: Help connecting SPI ST7789 lcd

Your most apparent problem is: CS is tied to 3v3 CS is an active low signal, which means that if you don't need to control it, you should tie it to GND. Another thing that doesn't seem right is the SPI phase and polarity. If my ST7789 screen is anything to go by, both should be set to 0. Other than ...
by horuable
Thu Jul 08, 2021 9:44 pm
Forum: General
Topic: Help reading LM35 temp sensor with pico
Replies: 7
Views: 340

Re: Help reading LM35 temp sensor with pico

What output do you expect to see?

According to datasheet LM35 have accuracy ranging from 0.5 to 1.5 C at around 25 C, depending on exact part number.
by horuable
Thu Jul 08, 2021 12:19 pm
Forum: General
Topic: Help reading LM35 temp sensor with pico
Replies: 7
Views: 340

Re: Help reading LM35 temp sensor with pico

ADC reference in Pico is 3.3V and doesn't depend on how you power your sensor, so you should use:

Code: Select all

conversion_factor = 3.3/65535
With this correction, your example gives around 31 C, which seems a bit more reasonable.
by horuable
Mon Jul 05, 2021 4:42 pm
Forum: MicroPython
Topic: good edge timing accuracy in MicroPython?
Replies: 42
Views: 3129

Re: good edge timing accuracy in MicroPython?

People really need to stop writing PIO code which only gets assembled without error because the PIO assembler does almost no error checking. "mov" is not "set" which is what I presume the code intended. I'm the author of this code, so I feel like I have to say something. You are...
by horuable
Sun Jul 04, 2021 4:53 pm
Forum: MicroPython
Topic: sdcard.py, no sd card error
Replies: 33
Views: 1563

Re: sdcard.py, no sd card error

That's because if the card is not in the reader the OSError is raised on SDCard object initialisation, so you should have your try-except around that, e.g.:

Code: Select all

try:
    sd = sdcard.SDCard(sd_spi, Pin(26, Pin.OUT))
    print("card detected!")
except OSError:
    print("no card")
by horuable
Thu Jul 01, 2021 8:57 pm
Forum: MicroPython
Topic: Reading out the operating system of the computer connected via USB
Replies: 12
Views: 544

Re: Reading out the operating system of the computer connected via USB

AFAIK MicroPython for Pico doesn't currently have HID support, so making a macro pad is not that easy. Your best bet would be to write a PC app that would receive commands from Pico via USB serial and take whatever action you want. Such an app could detect an operating system on its own and use prop...
by horuable
Mon Jun 28, 2021 4:12 pm
Forum: General
Topic: Pi pico on r/c sub
Replies: 5
Views: 412

Re: Pi pico on r/c sub

Take a look into this thread: viewtopic.php?f=146&t=308269, it should get you started.

Go to advanced search