Closed mytechnotalent closed 3 years ago
micro:bit support #42332
Also raised by Paralax on micro:bit support. This works on V1 but not on V2
Which pin do you set the period on?
Note that the ValueError: invalid period
error is just passed on from CODAL.
@dpgeorge I used pin0
and pin1
both together and separately.
If they are passed on from CODAL it might be beyond the scope of this repo perhaps @dpgeorge @microbit-carlos?
The issue is that the CODAL does not allow changing the analog period on pins that are not configured in analog-out mode. But I think this is how v1 DAL behaved so I don't believe it's an issue with CODAL.
Should be fixed for MicroPython by 6e0273fc4b6b83064912c260f75854f85ab39c6f
@mytechnotalent did you test this with the CI build? If so does your thumbs-up mean "works for me"?
@jaustin I promise to be more explicit next time my apologies again.
I git checkout 6e0273f
and build and flashed and what the ValueError
is in fact fixed. Tested and good to merge to main.
>>> from microbit import pin1
>>> pin1.set_analog_period(20)
>>> from microbit import pin0
>>> pin0.set_analog_period(20)
>>>
Thanks Kevin! I'll mark this as fixed.
Hi, I still have this issue. I try to both pin1.set_analog_period(20) and pin1.set_analog_period_microseconds(20) in both Thonny an Mu and still have the error. My workaround is to pin1.write_analog(0) before trying to pin1.set_analog_period(20). I’m using version 2.0.0-beta.5 .
Sorry for this question, I’m new to robotics, should I be able tu use all values (0 to 1023) after setting pin1.set_analog_period(20)? Because it seems to me that I can only use 0 to 300 (or similar), the remaining values produce nothing or odd behavior in kitronik servo motors.
Are you sure you are getting the same error ValueError: invalid period
? If I flash this programme with the latest version in the Python Editor I do not get any errors:
# Add your Python code here. E.g.
from microbit import *
pin1.set_analog_period(20)
Could you provide a minimum programme that throws your error? Maybe it's related to some other parts of the code.
Sorry, my fault!!! I was so sure I was using beta-5... three days spent on this... so frustrating!
Again, sorry.
No worries, glad you got it working in the end! 👍
i am making robotic car project in that i have to control dc motor with pwm signal using microbit. so i have written code for that which i combined digital write and analog write pins which part i am attaching below. But code is working only one time after that its not working(error - microbit led is flickering). how can i resolve this error?
pins.digital_write_pin(DigitalPin.P1,0) pins.digital_write_pin(DigitalPin.P2,0) pins.digital_write_pin(DigitalPin.P8,1) pins.digital_write_pin(DigitalPin.P12,0) pins.analog_write_pin(AnalogPin.P0,511) pins.analog_set_period(AnalogPin.P0,200) pins.analog_write_pin(AnalogPin.P3,511) pins.analog_set_period(AnalogPin.P3,200)
Hi @Darshnik253, You might be using some pins that are shared with the display (like P3). You can see the pin out here: https://tech.microbit.org/hardware/edgeconnector/#edge-connector-pins
thank you @microbit-carlos its solve. but getting another problem in that bluetooth UART service and serial communication using USB if i combined code both of them then after 11 times its not working can u just guide me in that?
As discussed @microbit-carlos:
When setting:
set_analog_period(20)
I am getting:
ValueError: invalid period
I have tried other values but same result on V2. 12/21 firmware on the v/beta web editor.