Comments (10)
Seems like having both options could be good. Universally usable code is brilliant, but the option to do it like it's done now also super handy. I don't know if this creates more overhead in the long run though. Having the option to specify UART pins feels like something people will inevitably want.
from adafruit_blinka.
the thing that will bite people with RX/TX is that you need to map that to the UART name-path ... and that changes sometimes when OS's change :/
from adafruit_blinka.
We chatted about this earlier and decided to try passing in a Serial object from pyserial instead of adding a busio.UART. The drivers will hopefully just work with it.
from adafruit_blinka.
@kattni wanna take a look at both our UART and the official 'pyserial' api, see if it matches up? we'll of course try with real code but take a glance! :)
from adafruit_blinka.
As long as the options work the same, pyserial does everything our UART does. pyserial does way more than our UART does but all the same options are there. Sounds worth testing!
from adafruit_blinka.
well, the API is the same, but encoding is Fun - here's the diff i had to make to adafruit_gps, string literals needed a b' prefix. variables needed a bytes(var, encoding="UTF-8")
beyond this it 'just worked' tho
adafruit_gps.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/adafruit_gps.py b/adafruit_gps.py
index 66d0eee..3086840 100644
--- a/adafruit_gps.py
+++ b/adafruit_gps.py
@@ -115,15 +115,15 @@ class GPS:
Note you should NOT add the leading $ and trailing * to the command
as they will automatically be added!
"""
- self._uart.write('$')
- self._uart.write(command)
+ self._uart.write(b'$')
+ self._uart.write(bytes(command, encoding="UTF-8"))
if add_checksum:
checksum = 0
for char in command:
checksum ^= ord(char)
- self._uart.write('*')
- self._uart.write('{:02x}'.format(checksum).upper())
- self._uart.write('\r\n')
+ self._uart.write(b'*')
+ self._uart.write(bytes('{:02x}'.format(checksum).upper(), encoding="UTF-8"))
+ self._uart.write(b'\r\n')
@property
def has_fix(self):
from adafruit_blinka.
circuitpython does not seem to support bytes w/encoding (brennen tried this for me)
@tannewt any ideas?
>>> bytes("Hello world", encoding="UTF-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: wrong number of arguments
from adafruit_blinka.
For the record, I think "Hello world".encode("UTF-8")
should work. This is risky however because you actually want ascii bytes instead of encoded unicode. So, I recommend using b"Hello world"
instead.
from adafruit_blinka.
ok we resolved this over hipchat, we'll use b' as much as possible and then .encode() when we can't
from adafruit_blinka.
turns out encode() doesnt work in CircuitPython. the correct universal technique is
bytes("hello world", "utf-8")
going thru libraries now, no changes needed to underlying circuitpython busio device but might be good to restrict circuitpython busio.uart to bytes only, rather than letting strings slide thru (in 4.0?) - lemme know if you agree and i can open an issue
from adafruit_blinka.
Related Issues (20)
- DietPi - Error installing Adafruit-Blinka HOT 1
- any check scripts that should be performed before issuing a PR for adding a new board
- Adafruit-PlatformDetect version 3.66.0 was unable to identify the board HOT 3
- Cant find the board HOT 6
- Some microcontroller definitions may be incorrect.
- libgpiod_pin_1_x.py does not detect internal pulldowns HOT 1
- GT911 touch sensor support for Adafruit Blinka HOT 7
- adafruit-circuitpython-motor fails with "RuntimeError: Cannot determine SOC peripheral base address" on Raspberry Pi 5 HOT 12
- Adafruit-Adafruit-PlatformDetect version 3.69.0 was unable to identify the board HOT 13
- Adafruit-PlatformDetect version 3.69.0 was unable to identify the board HOT 2
- support for NXP i.MX 8M PLUS HOT 3
- pip try to install sysv-ipc on Windows HOT 26
- It is no longer possible to install from 8.44.0. HOT 4
- Getting error in WCMCU-200 I2c to USB Adapter
- Add New Board adafruit FT232H Breakout for adafruit-blinka HOT 3
- Add Orange Pi AIPro
- Remove dependency to numpy HOT 2
- RPi GPIO is not support for Pi 5 any more, why merge pi5 with pi4 under board? HOT 3
- BananaPI F2P
- Maker Pi RP 2040 not supported. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit_blinka.