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)
- Jetson Orin Nano no SCLK_1 HOT 3
- MCP2221A import board error issue HOT 2
- Mellow Fly Pi V2
- add support in Blinka for orange pi zero 3 HOT 1
- running the Windows platform. HOT 1
- ft232h output signal HOT 1
- ft232h with MLX90640 HOT 2
- Big Tree Tech BTT pi
- RPI 5 - python library piod: 'Chip' has no attribute 'OPEN_BY_NUMBER' HOT 24
- Breadboard HOT 2
- Arduino Uno HOT 5
- STM32F405 Feather Request
- rpi_ws281x not compatible with pi 5 HOT 4
- Exception thrown in Lockable.unlock() does not follow CircuitPython behavior
- Raspberry Pi5 RuntimeError: Timed out waiting for PulseIn message. Make sure libgpiod is installed. HOT 6
- Please add support for the OrangePiCM4 HOT 3
- board HOT 1
- Accessing digitalio CE0 results in a device busy error on Pi5 HOT 20
- RP2040 fails on valid UART pin combinations HOT 2
- AttributeError: pin instead of pin.id HOT 1
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.