1

I've been trying to send the data from my camera that is connected to my raspberry pi to the RS485 board.

Since the RS485 board is connected to the UART, then I tried to send the data like just sending data to the UART, however I'm not getting any data in the RS485 board. (Do I need to convert the bytes to bits? Is it all possible to do?) Here is the python code:

#!/usr/bin/env python      
import serial
import time
import struct
import datetime
def main():
    cam = serial.Serial('/dev/video0',38400,timeout=0.1)
    camset(cam)
    capture(cam)
    ser = serial.Serial(             
        port='/dev/ttyAMA0',
        baudrate = 115200,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
    )
def camset(cam):
    time.sleep(0.25)
    print(cam)
    # reset
    cam.write(b'\x56\x00\x26\x00')
    time.sleep(1.0)
    read(cam)
    print('finish setting...')
def capture(cam):
    # takepic
    cam.write(b'\x56\x00\x36\x01\x00')
    read(cam)
    time.sleep(2.0)
    # getsize
    cam.write(b'\x56\x00\x34\x01\x00')
    time.sleep(1.5)
    print('size')
    a = str()
    a = cam.readline()
    kh = int(a[len(a)-2])
    kl = int(a[len(a)-1])
    print(kh,kl)
    readpic(cam,kh,kl)
    cam.write(b'\x56\x00\x34\x01\x03')
    cam.close()
def readpic(cam,kh,kl):
    s = b'\x56\x00\x32\x0C\x00\x0A\x00\x00'
    u = b'\x00\x00'
    w = b'\x00\x0A'
    # address
    t =  bytes([0]) + bytes([0])
    # size
    hx = bytes([kh])
    lx = bytes([kl])
    v = hx + lx
    cam.write(s+t+u+v+w)
    binary = cam.readline()
    a = binary
    while a:
        time.sleep(0.05)
        a = cam.readline()
        binary = binary + a
    print('finish readline...')
    # modify binary
    binary = binary[binary.find(b'\xff\xd8'):binary.rfind(b'\xff\xd9')+2]
    # sending data to the UART (RS485 connected)
    ser.write(binary)
    print('ended!')
def read(cam):
    a = cam.readline()
    while a:    
        print(a)
        time.sleep(0.1)
            a = cam.readline()
if __name__ == '__main__':
    main()
6
  • 1
    In some format, and at 38400 baud quite slowly - more occasional pictures than video. But you don't seem to explain what the problem with your attempt is. Additionally this is not really on topic here since your problem appears to be with generic python-based software not electronics or any embedded-specific software task. – Chris Stratton Mar 18 '17 at 0:09
  • What rs485 board and what wiring? – Marko Buršič Mar 18 '17 at 0:10
  • 1
    Probably you should back up and monitor the UART data before the RS485 board. You should also state how you plan to drive its output enable. – Chris Stratton Mar 18 '17 at 0:11
  • Well I thought it was eletronics because I've been told that one of the problems could be the type of data I'm sending or RS485 support, so I wanted to know if it's actually feasible the data sending of pictures to the RS485. The wiring and rs485 I'm using is homegear.eu/images/1/10/RS485_Serial_Module_Wiring.png – rookie2017 Mar 18 '17 at 0:16
  • As you see is UART – rookie2017 Mar 18 '17 at 0:16
1

The problem is probably in the low level driver implementation. As you see there are 2 GPIOs that you have to control them. I guess one of them is TX- enable and the other probably RX-enable. You could probably join both signals to a single one, which could be named RTS (request to send). All you have to do is to init your UART with RTS functionality, and declare that GPIOxy is the RTS.

1

Could be a typo, and I don't know python at all, but :

cam = serial.Serial('/dev/ttyAMA0'

And

ser = serial.Serial(          
port='/dev/ttyAMA0',

Would seem to be referring to the SAME SERIAL PORT.... I very much doubt that having both pointing at the same port is going to end well.

1

This line

cam = serial.Serial('/dev/video0',38400,timeout=0.1)

will never work. You cannot read a video device as if it was a serial device, or a file, or a network interface, etc. You must configure the camera (with frame size and format, not the baudrate!) and tell it to start a photo / video capture, before you can use read() to get the actual data.

Check out the V4L2 API to learn how to use a video device in Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.