Code Monkey home page Code Monkey logo

Comments (6)

MarcinKlima avatar MarcinKlima commented on May 18, 2024 1

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.

PowerBroker2 avatar PowerBroker2 commented on May 18, 2024

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.

MarcinKlima avatar MarcinKlima commented on May 18, 2024

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.

PowerBroker2 avatar PowerBroker2 commented on May 18, 2024

I've fixed the examples and will tag out a new version soon.

from pyserialtransfer.

MarcinKlima avatar MarcinKlima commented on May 18, 2024

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.

PowerBroker2 avatar PowerBroker2 commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.