Persistant Error message

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
geotek
 
Posts: 65
Joined: Thu Mar 07, 2013 1:39 pm

Persistant Error message

Post by geotek »

Greetings:

I have two very frustrating problems
First -- I have a mono Adafruit ssd1306 display which I believe is defaulted to I2c 0x03.
I have installed the circuitpy.uf2 file and the three support files in a LIB folder and tried some simpletest.py programs but I caanot get the display to display anything at all. I also get error messages for the I2c address

Second -- I have tried a i2c scan program below and I get the following error message:

ImportError: no module named 'machine'
-------------------------------------------------------------------------------------------------------------------------------

Code: Select all

import machine
sda=machine.Pin(0)
scl=machine.Pin(1)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
 
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
  for device in devices:  
    print("Decimal address: ",device," | Hexa address: ",hex(device))
I am using a RPI Pico and a laptop with Thonny and also have MU instaled
I am getting frustrated and need some further guidance
Thanks in advance
Tom

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Persistant Error message

Post by dastels »

I don't see a module named machine. Try microcontroller.

Make sure the code is running on the Pico, and not your PC. I've seen this happen a lot with Thonny.

Dave

User avatar
geotek
 
Posts: 65
Joined: Thu Mar 07, 2013 1:39 pm

Re: Persistant Error message

Post by geotek »

Dave

I still do not understand - where does this module “ machine”reside?
I often see it called , in various program, but don’t know where is comes from? Or what it actually is?
If I try to run the simple scan program show in my post there is no other file or support file for it.
You mention below ‘try microcontroller’ — what do mean by -try microcontroller?

I don't see a module named machine. Try microcontroller.
Also HowDo I run Circuit.mpy programs?
Thanks
Tom

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Persistant Error message

Post by dastels »

I don't see a machine module anywhere. Not in the bundle and not in the runtime. There are many modules that are implemented in C++ and are part of the CircuitPython runtime, especially very low level and/or performance sensitive ones. See https://circuitpython.readthedocs.io/en ... atrix.html to see what is included for each board.

However, looking closer, your approach to creating the I2C object is incorrect.

For the Pico you should use:

Code: Select all

import board
import busio

i2c = busio.I2C(scl=board.GP1, sda=board.GP0)
See https://learn.adafruit.com/getting-star ... cuitpython for more information on the PiPico and using it with CircuitPython.

I'm guess but I assume that by
Also HowDo I run Circuit.mpy programs?
you mean how do you run CircuitPython programs?

For simple programs that are just a single file, that file should be saved to the CIRCUITPY drive in a file named code.py

If your program is in multiple files you will have a main file that does setup and typically contains the main loop. That's the file CircuitPython should load and execute when it starts. That can likewise be named code.py but it's a bit clearer to name it main.py

That's it one of those two names. If you don't do that CircuitPython won't see your code.

Files ending in MPY are pre-byte-compiled python code. PY files (python source code) get byte-compiled as they are loaded. MPY files are already byte-compiled (using the mpy-cross program) so they are faster to load and don't use RAM to compile them (since they already are). For example libraries in the bundle are pre-byte-compiled MPY files.

Something just occurred to me... was that code written for MicroPython? That might explain the differences.

Dave

User avatar
geotek
 
Posts: 65
Joined: Thu Mar 07, 2013 1:39 pm

Re: Persistant Error message

Post by geotek »

Dave

Thanks for clearing up some of my Circuitpython question.
I have been trying to run both micropython and circuitpython programs.
Sorry for the confusion - yes the scan program was a micropython program lifted from somewhere to try and scan I2c when set up in micropython. So I found that program supposedly for a Pico to scan I2c ports. So then - where does the import’ machine program come from when trying to run Micropython I2c program. Is there a ‘Machine’ micropython library that has to be called From somewhere? If so where is it?
Thanks
Tom

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Persistant Error message

Post by tannewt »

`machine` is a native module in MicroPython so its source is C code in the MicroPython repo.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”