Comments (6)
Yes im lost 2 days :) for that, mega good library for me.
And numpy and its data types save my life :)
y = np.float16(0.0) etc.
Thank U for support.
from pyserialtransfer.
Without looking at your code, you're most likely not using 32 bit floats on the Arduino side. If you replace float
with double
, you should be good to go.
from pyserialtransfer.
Yes, my mistake, is fact.
But when im try examples from GIT, nothing working, only CHAR variable has expected value, in y have 0.0, arr has "nothing".
Raw example generate like this:
unpacked_response = unpacked_response.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xeb in position 3: invalid continuation byte
Arduino:
#include <Arduino.h>
#include <Wire.h>
#include <SerialTransfer.h>
HardwareSerial Serial2(PA3,PA2);
SerialTransfer myTransfer;
struct STRUCT {
char z;
double y;
} testStruct;
char arr[] = "hello";
void setup() {
Serial2.begin(9600);
myTransfer.begin(Serial2);
analogWriteResolution(12);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
testStruct.z = '$';
testStruct.y = 5.25;
}
void loop() {
// use this variable to keep track of how many
// bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;
///////////////////////////////////////// Stuff buffer with struct
sendSize = myTransfer.txObj(testStruct, sendSize);
///////////////////////////////////////// Stuff buffer with array
sendSize = myTransfer.txObj(arr, sendSize);
///////////////////////////////////////// Send buffer
myTransfer.sendData(sendSize);
testStruct.y = testStruct.y + 0.1;
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
}
Python:
from time import sleep
from pySerialTransfer import pySerialTransfer as txfer
class struct(object):
z = ''
y = 0.0
arr = ''
if name == 'main':
try:
testStruct = struct
link = txfer.SerialTransfer('/dev/ttyUSB0', baud=9600)
link.open()
sleep(5)
while True:
if link.available():
recSize = 0
testStruct.z = link.rx_obj(obj_type='c', start_pos=recSize)
recSize += txfer.STRUCT_FORMAT_LENGTHS['c']
testStruct.y = link.rx_obj(obj_type='f', start_pos=recSize)
recSize += txfer.STRUCT_FORMAT_LENGTHS['f']
arr = link.rx_obj(obj_type=str,
start_pos=recSize,
obj_byte_size=6)
recSize += len(arr)
print('{}{} | {}'.format(testStruct.z, testStruct.y, arr))
elif link.status < 0:
if link.status == txfer.CRC_ERROR:
print('ERROR: CRC_ERROR')
elif link.status == txfer.PAYLOAD_ERROR:
print('ERROR: PAYLOAD_ERROR')
elif link.status == txfer.STOP_BYTE_ERROR:
print('ERROR: STOP_BYTE_ERROR')
else:
print('ERROR: {}'.format(link.status))
except KeyboardInterrupt:
link.close()
from pyserialtransfer.
I've fixed the examples and will tag out a new version soon.
from pyserialtransfer.
Ok, find where is problem, im don`t know is the platform STM32/ARDUINO or python issue - but difference bet wen sides is
arduino - recsize is 12... on python showing 8. when im add(4) to be 12 on python, everything work ok. Why?
from pyserialtransfer.
The issue isn't on either side, it's how you use the libraries. Python's normal float size is 32 bits and Arduino's normal float size is 16 bits. If you use doubles on the Arduino side, or 16 bit floats on the Python side, you'll be good to go
from pyserialtransfer.
Related Issues (20)
- AttributeError occurs HOT 4
- Examples use double on Arduino side, format 'f' on python side HOT 9
- Arduino tx_data + pySerialTransfer rx_data example fails with esp32 Arduino HOT 6
- Want support for transferring bytes() HOT 1
- Transferring Integers Rather than Float/Double HOT 2
- Problem with the example scripts HOT 7
- Typo in example file and logical error HOT 4
- Error when tryinf to receive integer HOT 1
- Parsing char from Arduino side HOT 6
- Example code error. size mismatch?
- how to use data sent from python in arduion? HOT 1
- How to transmit large array of floats fast and reliably? HOT 2
- Check for CRC error HOT 1
- Sending a Boolean HOT 5
- Is there a maximum variable size for "x" when using myTransfer.sendDatum("x")? HOT 12
- Serial port doesnโt stay connected HOT 2
- Send encoder data HOT 6
- Can we use this library on Raspberry Pi for communication through GPIO? HOT 2
- Are there any examples showing how to save received file to a PC folder. HOT 1
- Data array sometimes gets corrupted if some values are present HOT 5
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 pyserialtransfer.