0

I connected this sensor with raspberry via UART( I have found that this IR sensor is one of few Lego sensors that connects via UART), and make serial_read and serial_write python scripts, just to test it, but nothing happens (I have dump printed on console). (Before that, I went through whole uart enabling process , enable_uart=1 etc.). On Lego site I have found that after cable connection with sensor, it should start working without any additional setups, but that works with connection between sensor and EV3 brick.(actually first they exchange ack messagge, and then communication begins).

serial_read.py code

#!/usr/bin/env python

import time
import serial


ser = serial.Serial(

  port='/dev/ttyUSB0',
  baudrate = 9600,
  parity=serial.PARITY_NONE,
  stopbits=serial.STOPBITS_ONE,
  bytesize=serial.EIGHTBITS,
  timeout=1
  )

  while 1:
      x=ser.read()
      print str(x)

I think that problem is because I am starting communication without ack ( for which I don't know how to implement, there isn't any words about this messagge in docs) messagge, does anybody have similar expeirence?

When I try to send from serial port to cloud, (with java kura framework) I have Error during component activation java.lang.NullPointerException

*******************EDIT************************

I connected sensor to USB port of my computer, and used Tera term...

This is what I get :

Baud rate 9600 gives me only Xxxxxxxx and circles symbols.

Baud rate 2400 :

enter image description here

****************************** EDIT v3 ****************************************

From LEGO manual: For UART: " To enable bi-directional and faster communication to external devices the EV3 platform supports UART communication on its input ports. The UART communication functions as asynchronous communication, supporting from 2400 bit/s to 460 Kbit/s on port 1 & 2, while ports 3 & 4 supports up to 230 Kbit/s. The UART communication uses 1 stop bit, 8 data bits and 1 stop bit. To establish UART communication between the EV3 Programmable brick and an external device a specific communication sequence should be followed."

For communication: The external devices start by transmitting back all it configuration values to enable the EV3 Programmable brick to update the system accordingly. Configuration data includes: - Start by keeping UART Tx-pin low for minimum 500 mS. (This will indicate a break condition).

  • Device type

  • Number of mode the device supports

  • Supported UART communication speed

  • It then starts communicating the individual modes supported. The default mode for the device needs to be communicated within mode 0 which also needs to be the last transmitted mode. Start with transmitting the highest mode and end with transmitting mode 0. Good practice is to add 10mS delay between each mode (IE. Transmit all relevant data for the mode and then wait 10 mS before starting in the next mode). o Mode name o Raw value range o SI value range o Symbol o Data format (This data ends the current mode information)

  • After having sent all relevant mode data the external device should send an ACK and start waiting on an ACK form the EV3 programmable brick. If no ACK is received within 80 mS the external device should reset as not receiving an ACK from the EV3 programmable brick means that the EV3 programmable brick has encounter an error during the communication. By resetting it should automatically start sending its relevant data again.

  • When an ACK is received the EV3 programmable brick has acknowledge the data and will switch to the requested communication speed and are ready to start receiving data from mode zero.

  • Please reference the protocol documentation towards how data needs to be packages when sending them back to the EV3 programmable brick. If the data is not packages correctly the EV3 programmable brick will not be able to handle the data correctly.

  • The EV3 programmable brick automatically sends a NACK command to the external devices every 300 mS. The MINDSTORS EV3 sensors uses this command to reset the internal watchdog timer within the sensor. This enables the EV3 programmable brick and the sensors to continuously be in sync. The MINDSTORMS EV3 sensors re-transmits the last valid data value upon this request. If no feedback values are received within 5 NACK request the NACK command is not send from EV3 programmable brick, this will result in the watchdog not being reset. The EV3 programmable brick will expect a watchdog timeout within the external device which will result in a reset of the external element.

  • 1
    The Pi's UART is 3V3. Is the sensor 3V3? If it's more than 3V3 you may have damaged the Pi's RXD pin and/or Pi. – joan May 3 '17 at 13:24
  • I connected IR sensor and raspberry with serial to USB cable, so sensor is connected to usb port... – MGKP May 4 '17 at 13:09
  • That is a safer method (assuming the USB end is plugged in to the Pi), hopefully no damage was done previously. If 2400 is the correct baud rate (what does the spec say?) then it's simply a programming problem to decode the data (again what does the spec say?). – joan May 4 '17 at 13:32
  • No damage was done, I checked pins with unimer... Here are some printscreens from spec : Digital sensor communication prnt.sc/f4cd7w IR Sensor: prntscr.com/f4cobg – MGKP May 5 '17 at 8:58
  • You need to add additional information to the body of your question. Text or a link to text is preferable to an image for text specifications. – joan May 5 '17 at 10:36
0

You can use ev3dev EV3 drivers on RaspberryPi.

That way you don't have to write the communication code yourself (just compile the driver and use sysfs to read sensor values).

See here for example:

https://lechnology.com/2014/09/using-uart-sensors-on-any-linux/#comment-22

And here:

https://github.com/ev3dev/lego-linux-drivers

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.