B4J Question Raspberry Pi + MAX485

dragonguy

Active Member
Licensed User
Longtime User
i totally no idea how to make it work, please give a little trick to start!

i connect the max485 to raspberry from this website https://www.homegear.eu/index.php/RS485_Serial_Module

but i totally no idea how to start B4J to make raspberry to receive or send data form device.

is it using jSerial to connect or need to use jPi4J?
i try jSerial but no luck.
here is my code
B4X:
Dim BaudRate As Int = config.Get("BaudRate")
    Log("BaudRate: " & BaudRate)
    Dim DataBits As Int = config.Get("DataBits")
    Log("DataBits: " & DataBits)
    Dim StopBits As Int = config.Get("StopBits")
    Log("StopBits: " & StopBits)
    Dim Parity As Int = config.Get("Parity")
    Log("Parity: " & Parity)
  
    sp.Open(config.Get("serial_port_path"))
    Log("Serial Port Path: : " & config.Get("serial_port_path"))
    sp.SetParams(BaudRate,DataBits,StopBits,Parity)
    astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")

didnt receive any data at all.

please help
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Interesting - If I try to open the link, google chrome blocks it! Firefox works.


Sorry but I find your code very hard to read when it is not clear what "config" is.

I think you only need jSerial: Serial and AsyncStreams. I have just done something similar, connecting a RS232 device via the USB to the RPi. If it helps in any way, you can have the source code.

You also don't say what is connected. If you send data to an open connection, nothing will happen! If you at least short Rx and Tx together, the sent data should come back.
 
Last edited:
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
Connection is like this image, download from that website.
 

Attachments

  • RS485_Serial_Module_Wiring.png
    RS485_Serial_Module_Wiring.png
    157 KB · Views: 5,899
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
My code work well with rs232, can receive and send Data. But now need to move to rs485.

Config is map function. I store my setting in text file and use map to read them.
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
RS485 ModulePC
DI (Driver Input)-UART TXD
RO (Receiver Output)-UART RXD
DE (Driver Enable)-Any GPIO
RE (Receiver Enable)-Any GPIO
VCC-3.3V or 5V, depending on your module
GND-Ground
Green color regarding to DE and RE
 
Upvote 0
Top