Jump to content

Recommended Posts

Posted

Hi,

I am using the TinkerForge RS232 V2 Module and want to read sensor data.

This is my code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# For this example connect the RX1 and TX pin to receive the send message

HOST = "localhost"
PORT = 4223
UID = "XXXX" # Change XYZ to the UID of your RS232 Bricklet 2.0

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_rs232_v2 import BrickletRS232V2

import time

# Callback function for read callback
def rs232_data_received(data):

    test = ''.join(data)
    print(test)

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    rs232 = BrickletRS232V2(UID, ipcon) # Create device object
    ipcon.connect(HOST, PORT) # Connect to brickd

    rs232.set_configuration(baudrate=9600,
                            parity=BrickletRS232V2.PARITY_NONE,
                            stopbits=BrickletRS232V2.STOPBITS_1,
                            wordlength=BrickletRS232V2.WORDLENGTH_8,
                            flowcontrol=BrickletRS232V2.FLOWCONTROL_OFF)

    # Don't use device before ipcon is connected

    print(rs232.get_chip_temperature())

    # Register read callback to function cb_read
    
    rs232.register_callback(rs232.CALLBACK_READ, rs232_data_received)

    # Enable read callback
    rs232.enable_read_callback()

    input("Press key to exit\n") # Use raw_input() in Python 2
    ipcon.disconnect()

 

The problem is, when I get the data output I only see unusual characters like this:

 

[
ý


¿

¿


å
ë
[
ý


å
ë

[
ý

 

When I use a FTDI Chip I can read the correct output (using pyserial). I also attached a LogicAnalyzer and the data shows fine. So I think it is a problem of converting the Data (Baudrate is correct).

Since I do not now what in the middle "layer" of TinkerForge is happening with the data, can someone please help me how to convert the data into correct ascii Numbers?

Many thanks

Posted

How did you conect the sensor to the Bricklet? You have to connect it to the pin header which expects 3.3V TTL signals. You cannot connect it to the D-Sub 9 connector nor the terminal block, both expect RS232 voltage levels. I think you also need to power the sensor with 3.3V to make it output 3.3V TTL signals.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...