Search found 3821 matches

by dhylands
Mon Apr 04, 2022 5:07 am
Forum: ESP32 boards
Topic: Can Micropython and C modules share the same FAT filesystem?
Replies: 2
Views: 1191

Re: Can Micropython and C modules share the same FAT filesystem?

The C code can use the same filesystem but it needs to use use the python functions to read/write/open/close the file and not use the c runtime library (I.e. fread/fwrite/fopen/fclose). An example of how to do this can be found in the mpfile.c file from this commit: https://github.com/dhylands/micro...
by dhylands
Mon Apr 04, 2022 4:54 am
Forum: General Discussion and Questions
Topic: bug in constructor with default value. [SOLVED]
Replies: 5
Views: 1849

Re: bug in constructor with default value.

Using [] or {} as default arguments is almost always a mistake. See this blog post which describes why in more detail: https://nikos7am.com/posts/mutable-default-arguments/ You’d be better to use a default value of None and then inside your function do something like: if arg is None: arg = [] This w...
by dhylands
Fri Mar 04, 2022 7:22 pm
Forum: Raspberry Pi microcontroller boards
Topic: Sized Integers
Replies: 1
Views: 1159

Re: Sized Integers

Micropython has 2 representations of an integer. One is SMALLINT which doesn't require heap allocation and is a 31-bit signed number. The second is an infinite precision integer which can have as many digits as it needs. For creating sized data structures, for storing to disk, sending over the seria...
by dhylands
Fri Mar 04, 2022 6:20 pm
Forum: General Discussion and Questions
Topic: Repeatable, periodic glitch in timer
Replies: 4
Views: 2130

Re: Repeatable, periodic glitch in timer

Probably the thing to do then would be to have your timer callback use micropython.schedule to schedule a function to run. Things scheduled by micropython.schedule will run "between" VM instructions. This will give you minimal jitter while still being able to call i2c functions.
by dhylands
Fri Mar 04, 2022 6:04 pm
Forum: MicroPython pyboard
Topic: Basic Timer Question
Replies: 4
Views: 2960

Re: Basic Timer Question

Hi Dave I adjusted the code based on your response and the example you provided as below: import pyb def light(tim): led = pyb.LED(4) led.toggle() tim = pyb.Timer(1, freq=10) # freq in Hz tim.callback(light) This now works as expected. I left led as a local variable for now. I'm a little confused a...
by dhylands
Thu Mar 03, 2022 8:11 pm
Forum: General Discussion and Questions
Topic: Repeatable, periodic glitch in timer
Replies: 4
Views: 2130

Re: Repeatable, periodic glitch in timer

So the loops will gradually get out of phase with the timer, and you'll eventually wind up slipping by around 100 usec (the duration of your sleep). You'd need to time how long your loop actually takes to see if that contributes more. You'll get much less jitter if you toggle B4 from inside the time...
by dhylands
Thu Mar 03, 2022 6:58 pm
Forum: MicroPython pyboard
Topic: Basic Timer Question
Replies: 4
Views: 2960

Re: Basic Timer Question

Here's a link to my tested example using a closure:
https://github.com/dhylands/upy-example ... closure.py

It looks like tick needs to be a global. I couldn't get it to work as a local to the light function (I suspect that this is a microptyonism).
by dhylands
Thu Mar 03, 2022 6:40 pm
Forum: MicroPython pyboard
Topic: Basic Timer Question
Replies: 4
Views: 2960

Re: Basic Timer Question

You're passing the results of calling light(led) (which is None) to callback, instead of passing the function light to callback. Use this instead: tim.callback(light) The light callback needs to take a single argument, which is the timer its associated with. So you'll either need to make led be a gl...
by dhylands
Wed Mar 02, 2022 6:18 am
Forum: MicroPython pyboard
Topic: UART half duplex for Dynamixel servos
Replies: 7
Views: 4556

Re: UART half duplex for Dynamixel servos

Yes that's right the dynamixel is a 5v data line. Is the UART pin the the STM32 5v tolerant as the dynamixel sends back 5v Yes the STM32F4 UART lines are 5v tolerant. Did you also need a pull-up on the data line or did the STM32F4 pull-up the line when idle?? I think I must have had a pullup on the...