Hi,
I'm trying out a simple code to turn ON an external LED on https://micropython.org/unicorn/. But I get an import error while importing 'Pin' attribute. Can someone guide me here? Please look at the code below:
>>> from pyb import Pin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name Pin
>>> import pyb
>>> from pyb import Pin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name Pin
>>>
Import error - using Micropython onilne
Re: Import error - using Micropython onilne
The unicorn demo isn't quite the same as a pyboard. If you want to access a pin, you can use `machine.Pin`. Have a look at the "pin led" demo.
(FYI, even on a real pyboard, the `pyb` module is mostly deprecated in favour of the `machine` module).
(FYI, even on a real pyboard, the `pyb` module is mostly deprecated in favour of the `machine` module).
Re: Import error - using Micropython onilne
The libraries are pretty confusing - I'm not able to use the Timers as well in the unicorn.
import pyb
tim=pyb.Timer(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Timer'
Timer class doesn't exist in machine, pyb nor time modules. Can someone help me how to declare 'tim' variable?
import pyb
tim=pyb.Timer(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Timer'
Timer class doesn't exist in machine, pyb nor time modules. Can someone help me how to declare 'tim' variable?
Re: Import error - using Micropython onilne
The unicorn-based demo isn't actually a pyboard. It's simulating a virtual device with a UI that just happens to look like a pyboard.
However, in order to make a limited number of existing scripts work, the authors provided a very minimal copy of the `pyb` module, but it only provides `Switch`, `LED`, `Servo` and `ADC`. There is no support for timers in the simulator.
You can see the implementation at https://github.com/micropython/micropyt ... er/unicorn
However, in order to make a limited number of existing scripts work, the authors provided a very minimal copy of the `pyb` module, but it only provides `Switch`, `LED`, `Servo` and `ADC`. There is no support for timers in the simulator.
You can see the implementation at https://github.com/micropython/micropyt ... er/unicorn
Re: Import error - using Micropython onilne
Oh! I was hoping there would be a different way to implement the functionality. Thank you for the clarification!