Search found 1890 matches

by Roberthh
Sun Apr 05, 2020 8:05 pm
Forum: General Discussion and Questions
Topic: How to check if file exists?
Replies: 2
Views: 57

Re: How to check if file exists?

You can use the try/execpt mechanism of Python, trying to open the file, or "stat" the file. e.g.:

Code: Select all

try:
    f = open(filename, "r")
    # continue with the file.
except OSError:  # open failed
   # handle the file open case
by Roberthh
Sat Apr 04, 2020 6:22 pm
Forum: Programs, Libraries and Tools
Topic: How to adapt a python library to micropython?
Replies: 8
Views: 169

Re: How to adapt a python library to micropython?

Since I do not have you actual code, I guess it is the line: reg = self.i2c.readfrom_mem(I2C_ADDRESS, MODE_CONFIG) It should be: reg = self.i2c.readfrom_mem(I2C_ADDRESS, MODE_CONFIG, 1)[0] The other lines with readfrom_mem() must be changed accordingly. I suggest reading the documentation. The chapt...
by Roberthh
Sat Apr 04, 2020 3:05 pm
Forum: Programs, Libraries and Tools
Topic: How to adapt a python library to micropython?
Replies: 8
Views: 169

Re: How to adapt a python library to micropython?

i2c.writeto_mem expected a buffer type argument with the data, not an integer. So you better make a local method, which packs the value into a 1 element bytearray. in __init__, you would create: self.xmit_data = bytearray[1] and then you'll defene a function like: def i2c_write(self, addr, reg, valu...
by Roberthh
Fri Apr 03, 2020 7:36 pm
Forum: Programs, Libraries and Tools
Topic: How to adapt a python library to micropython?
Replies: 8
Views: 169

Re: How to adapt a python library to micropython?

The code you refer to is for RPI. Porting that to MicroPython should be easy. It should be sufficient to replace the calls to i2c read_byte_data and write_byte_data to the matching calls of MicroPython, readfrom_mem and writeto_mem. The type of the parameters might be slightly different, but that's ...
by Roberthh
Sat Mar 21, 2020 9:11 pm
Forum: ESP8266 boards
Topic: Problem getting HMC5883L to work
Replies: 14
Views: 967

Re: Problem getting HMC5883L to work

Replace the wires to your breakout board. If that does not help, the chip may be broken.
by Roberthh
Sat Mar 21, 2020 7:51 pm
Forum: ESP8266 boards
Topic: Problem getting HMC5883L to work
Replies: 14
Views: 967

Re: Problem getting HMC5883L to work

qmc5883.ready() returning 0 means, that not data is available for reading. Are you sure that you did not change anything?
What is the result of calling:

qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 6)

or

qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 14)
by Roberthh
Fri Mar 20, 2020 10:30 am
Forum: ESP8266 boards
Topic: my esp8266 cannot recognize my sdcard
Replies: 2
Views: 112

Re: my esp8266 cannot recognize my sdcard

Which board and SD card adapter ate you using? It is also common that not every type of card works. Try a different card with a size <32 GB.
Edit: the card must have a single FAT partition only.
by Roberthh
Thu Mar 19, 2020 7:26 pm
Forum: General Discussion and Questions
Topic: Confusion about micropython.const
Replies: 4
Views: 191

Re: Confusion about micropython.const

The reason: variable assignment does not happen at compile time. It happens when the code is executed.
In comparison, the following works:

Code: Select all

ONE = const(1)
TWO = const(2)

COMPILED = const(ONE | TWO)
Note: You do not have to import const.
by Roberthh
Wed Mar 18, 2020 8:33 pm
Forum: General Discussion and Questions
Topic: UART ?
Replies: 2
Views: 618

Re: UART ?

If you do not specify rx, the default will be used. Which pin that is, depends on the board and UART number. The defaults e.g. for UART 2 on ESP32 are pin 16 and 17 and should not be used (old bug). The defaults for UART1 are pin 9 (rx) and 10 (tx).
by Roberthh
Wed Mar 18, 2020 5:02 pm
Forum: General Discussion and Questions
Topic: Proximity sensor using VL53L0x
Replies: 3
Views: 1012

Re: Proximity sensor using VL53L0x

It looks like the wrong place to ask. Better ask at the adafruit forum: https://forums.adafruit.com/