i want to make a monitoring program for tracer
i use rs485 usb converter to connect epever tracer1210a to raspberry pi 3 model b
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
client = ModbusClient(method = 'rtu', port = '/dev/ttyACM0', baudrate = 115200)
client.connect()
print( client)
result = client.read_input_registers(0x3100,6,unit=1)
print (result)
solarVoltage = float(result.registers[0] /100.0)
solarCurrent = float(result.registers[1] /100.0)
batteryVoltage = float(result.registers[4] /100.0)
chargeCurrent = float(result.registers[5] /100.0)
print("solar voltage : ",solarVoltage)
print("solar current : ",solarCurrent)
print("battery volatage : ",batteryVoltage)
print("charge current : ",chargeCurrent)
client.close()
and i get error like this:
ModbusSerialClient(rtu baud[115200])
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received)
Traceback (most recent call last):
File "yutub.py", line 9, in
solarVoltage = float(result.registers[0] /100.0)
AttributeError: 'ModbusIOException' object has no attribute 'registers'
please help me to fix this problem
I had faced the same problem.
Follow the below steps to fix the issue:
git clone https://github.com/kasbert/epsolar-tracer/tree/master/xr_usb_serial_common-1a
Follow the installation steps from Readme.
You might face problem when you execute make. In such case do sudo apt-get install linux-headers.
Check that the USB UART is detected by the system
lsusb
Check that the CDC-ACM driver was not installed for the Exar USB UART
ls /dev/tty*
To remove the CDC-ACM driver and install the driver:
sudo rmmod cdc-acm
sudo modprobe -r usbserial
sudo modprobe usbserial
sudo insmod ./xr_usb_serial_common.ko
After this when you do ls /dev/tty* you will see /dev/ttyXRUSB0. This means the driver is installed and you are in good shape.
Change the port in your code to '/dev/ttyXRUSB0'.
See the output image
After you restart the PI you might not see the ttyXRUSB0 instead you will see ttyACM0. In such case execute sudo echo blacklist cdc-acm > /etc/modprobe.d/blacklist-cdc-acm.conf. If PI does not allow you to execute then create the file in the path and write blacklist cdc-acm.
Reboot and verify if ttyACM0 is still displayed in ls /dev/tty*.
Related
I am trying to connect M210 v2 RTK to a desktop computer with Ubuntu 18.04, ROS Melodic and parallel installation of Opencv 3.3.1 and 4.5.3 using a USB-TTL RS232 to make UART connection and an USB-USB connecting drone and desktop to be able to run Advanced Sensing.
When I call ls -l /dev/ttyACM* && ls -l /dev/ttyUSB* it returns that it is indentified the USB and ACM connection.
crw-rw---- 1 root dialout 166, 0 out 4 13:18 /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 out 4 13:18 /dev/ttyUSB0
I also set the transfer rate of TTL-USB to 921600 using minicom, and gave persmission to device to read and write with sudo usermod -a -G dialout $USER && sudo chmod 666 /dev/ttyUSB0
Unfortunatelly when I launch roslaunch dji_osdk_ros dji_sdk_node.launch it appears some connection problem presented below and I am not being able to fix it. I have been trying to turn on/off drone and RC several times ass described here, but the problem still stand.
started roslaunch server http://V3D06:43613/
SUMMARY
========
PARAMETERS
* /dji_sdk/acm_name: /dev/ttyACM0
* /dji_sdk/align_time: False
* /dji_sdk/app_id: 1076017
* /dji_sdk/app_version: 1
* /dji_sdk/baud_rate: 921600
* /dji_sdk/dxc: False
* /dji_sdk/enc_key: 6bd1d26f8dd897e4b...
* /dji_sdk/serial_name: /dev/ttyUSB0
* /dji_sdk/use_broadcast: False
* /rosdistro: melodic
* /rosversion: 1.14.12
NODES
/
dji_sdk (dji_osdk_ros/dji_sdk_node)
auto-starting new master
process[master]: started with pid [2436]
ROS_MASTER_URI=http://localhost:11311
setting /run_id to bde7b4d2-252e-11ec-8a59-1831bfb3e154
process[rosout-1]: started with pid [2458]
started core service [/rosout]
process[dji_sdk-2]: started with pid [2464]
[ INFO] [1633364323.534426789]: Advanced Sensing is Enabled on M210.
Read App ID
User Configuration read successfully.
[1276751.089]STATUS/1 # getDroneVersion, L1702: ret = 0
[1276751.089]STATUS/1 # parseDroneVersionInfo, L1122: Device Serial No. = 1DADG3E00100U4
[1276751.089]STATUS/1 # parseDroneVersionInfo, L1124: Firmware = 3.4.3.44
[1276751.089]STATUS/1 # functionalSetUp, L279: Shake hand with drone successfully by getting drone version.
[1276751.089]STATUS/1 # legacyX5SEnableTask, L56: Legacy X5S Enable task created.
[1276752.089]STATUS/1 # sendHeartbeatToFCTask, L1576: OSDK send heart beat to fc task created.
[1276752.289]STATUS/1 # Control, L40: The control class is going to be deprecated.It will be better to use the FlightController class instead!
[1276752.290]STATUS/1 # FileMgrImpl, L253: register download file callback handler successfully.
[1276753.557]STATUS/1 # PSDKModule, L98: MOP only support M300, so mop client will not be initialized here.
[1276753.557]STATUS/1 # PSDKModule, L98: MOP only support M300, so mop client will not be initialized here.
[1276753.557]STATUS/1 # PSDKModule, L98: MOP only support M300, so mop client will not be initialized here.
[1276753.557]STATUS/1 # initDJIHms, L900: DJI HMS is not supported on this platform!
[1276753.567]STATUS/1 # getDroneVersion, L1702: ret = 0
[1276753.567]STATUS/1 # parseDroneVersionInfo, L1122: Device Serial No. = 1DADG3E00100U4
[1276753.567]STATUS/1 # parseDroneVersionInfo, L1124: Firmware = 3.4.3.44
[1276753.567]STATUS/1 # AdvancedSensing, L145: Advanced Sensing init for the M210 drone
[1276753.567]STATUS/1 # init, L49: Looking for USB device...
[1276753.572]STATUS/1 # init, L65: Found 8 USB devices, identifying DJI device...
[1276753.572]STATUS/1 # init, L83: Found a DJI device...
[1276753.572]STATUS/1 # init, L96: Attempting to open DJI USB device...
[1276753.572]ERRORLOG/1 # init, L101: Failed to open DJI USB device...
[1276753.572]ERRORLOG/1 # init, L102: Error code: -3
[1276753.572]ERRORLOG/1 # init, L105: Please make sure you provide a udev file for your system and reboot the computer
[1276753.573]STATUS/1 # LiveViewImpl, L89: Finding if liveview stream is available now.
[1276754.076]STATUS/1 # init, L254: Start advanced sensing initalization
[1276754.076]STATUS/1 # activate, L1329: version 0x304032C
[1276754.076]STATUS/1 # adv_pthread, L46: adv pthread created !!!!!!!!!!!!!!!!!!!!!!!
[1276754.076]STATUS/1 # adv_pthread, L48: adv pthread running !!!!!!!!!!!!!!!!!!!!!!!
[dji_sdk-2] process has died [pid 2464, exit code -11, cmd /home/vant3d/catkin_ws/devel/lib/dji_osdk_ros/dji_sdk_node __name:=dji_sdk __log:=/home/vant3d/.ros/log/bde7b4d2-252e-11ec-8a59-1831bfb3e154/dji_sdk-2.log].
log file: /home/vant3d/.ros/log/bde7b4d2-252e-11ec-8a59-1831bfb3e154/dji_sdk-2*.log
It appears it has some problem providing a udev file, but I don't know how to fix it. Does anyone have some idea to help on this problems?
Thank you!
That's my post. Firstly turn off advanced sensing to try whether a basic FTDI works.
The second which DJI OSDK version are you using? does the OSDK version match the version in OSDK-ROS? I saw you have M300 in. that is usually in OSDK 4+. For M210, I only use 3.8 and 3.9
If basic FTDI works, and you can get all the feedback. there is a higher chance that you have the wrong ACM config. DJI RNDIS thing is nasty and may not be config properly. You need to manually set static IP of 192.168.43.1 (or I remember something like this 42 or 43, you need to check on this static IP) and set it manually
this serial connection thing on RPi should not be this challenging, though right now I'm facing something quite weird
This is the code:
.
.
import serial
.
.
ser=serial.Serial(
port='/dev/ttyUSB0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
.
.
The Error is:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyUSB0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/rtu-v4/dnp3/rtu.py", line 27, in <module>
timeout=1
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 240, in __init__
self.open()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'
I alraedy checked out:
https://www.raspberrypi.org/forums/viewtopic.php?t=224369
https://github.com/brendan-w/python-OBD/issues/137
and ran the following commands in terminal:
sudo pip3 uninstall serial
sudo pip3 install pyserial
The Device is a Raspberry Pi 4
Any Help would be appreciated.
Thnx.
The message "No such file or directory: '/dev/ttyUSB0'" means that you do not have a device conected to you USB0.
You can use the command:
lsusb
to find out which ports are available and then change in you code de USB name to connect with the rigth device.
Since you are trying to communicate (I assume) with a USB to serial adapter, you can use dmesg to get the device that it is attached to the ttyUSB0.
In a terminal type this command:
dmesg|grep ttyUSB*
It will print out all the devices that are attached to all ttyUSBs.
In my case the result is:
[ 5072.316991] usb 3-1: ch341-uart converter now attached to ttyUSB0
If there were more devices connected, the result would have listed ttyUSB1/2..etc.
Should you disconnect the device, running the same command in a terminal will show the disconnection message:
dmesg|grep ttyUSB*
[ 5361.353142] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
I am establishing serial communication using raspberry Pi with ADAM-4520 device using pyserial lib using usb to serial converter.
1st,I tested device with PC using hyper terminal and with Pi using Gtkterm,
To read sensor values from device with command "#04".
Here i first giving output from Gtkterm.
#04
>+261.25+310.76+049.09+206.77+126.80+049.79
#04
>+261.25+310.76+049.09+206.75+126.80+049.79
But when i am trying through Pyserial program it isn't working.
Here is my code:
import serial
import time
s=serial.Serial(port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
st="#04"
st=''.join(str(ord(c)) for c in st)
x=st.encode('ascii')
while True:
s.write(x)
print(x)
time.sleep(0.2)
text=s.readline()
temp=text.decode('ascii')
#text=text.decode('utf-8')
#text=text[5:-1]
print(temp)
time.sleep(2)
As both hyper terminal and gtkterm work with ascii ,i am also tried to convert my command into ascii also but no result.
i am new to python ,please guide to find the issue guys
pi#raspberrypi:~ $ sudo python3 helloworld.py
b'354852'
b'354852'
b'354852'
Summary: Everything is connected, and appears to work, but no sound comes out of the speaker - how to diagnose or fix?
I am trying to play sound from my Raspberry Pi 3 to a bluetooth speaker, but it is not working.
The pi connects to the bluetooth speaker (confirmed by automated audio on the speaker when it connects, "raspberrypi connected", and checking echo "info 04:52:C7:5A:3B:A1" | bluetoothctl on the pi also shows it is connected).
The speaker volume is not muted and other devices can connect to it and play through it. Checking alsamixer verifies that audio is not muted.
But using aplay to play sound through the bluetooth speaker leads only to a deafening silence. Although it looks like it works:
$ aplay -D bluealsa:HCI=hci0,DEV=04:52:C7:5A:3B:A1,PROFILE=a2dp /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
I have looked for log files that might have information in them, but haven't found anything.
bluealsa configuration
I set this up following the instructions here. The details of this set up are:
Raspbian Stretch, 2018-10-09 image (bluealsa v5.43 installed out of box)
bluez v5.49 downloaded, built and installed (no errors)
/etc/dbus-1/system.d/bluetooth.conf edited, following lines added to root element:
<allow send_interface="org.bluez.ThermometerWatcher1"/>
<allow send_interface="org.bluez.HeartRateWatcher1"/>
<allow send_interface="org.bluez.CyclingSpeedWatcher1"/>
And following also added to the top level busconfig element:
<policy group="bluetooth"><allow send_destination="org.bluez"/></policy>
pi user added to bluetooth group
I have tried moving the HCI, device and profile details into .asoundrc and /etc/asound.conf files but these produce the same results (console output suggests successful, but no sound comes from the speaker when I use aplay).
Other things (probably not relevant but including for completeness)
pi access is via SSH (it's headless)
on booting the pi, sudo systemctl status blueto* shows an error message on the bluetooth service: Failed to set privacy: Rejected (0x0b), apparently a boot-related issue (link) which is fixed by manually restarting the bluetooth service after boot using systemctl (ugly, but fine as a workaround for now)
no suspicious looking messages in dmesg, user.log or boot.log
but the following was in daemon.log, it correlates with an execution of the aplay command above (but I have tried that command several times with the same console output, it generates them sometimes only):
.
Nov 10 21:02:16 rpi_3e5ccf bluealsa[789]: /usr/bin/bluealsa: Unsupported AT message: SET: command:+CLIP, value:1
Nov 10 21:02:16 rpi_3e5ccf bluealsa[789]: /usr/bin/bluealsa: Unsupported AT message: CMD: command:+CLCC, value:(null)
Nov 10 21:02:16 rpi_3e5ccf bluealsa[789]: /usr/bin/bluealsa: Unsupported AT message: SET: command:+CSRSF, value:0,0,0,1,0,0,0
Ultimately I was unable to debug this and got impatient, so just wiped the SD and started from scratch. The detailed steps I followed are below, these mean I can now play audio using aplay without having to specify the device, e.g.:
aplay /usr/share/sound/alsa/Front_Center.wav
1) Set up SD card image
use etcher to burn 2018-10-09-raspbian-stretch.img
touch /boot/ssh
add a suitable /boot/wpa_supplicant.conf file
edit /rootfs/etc/hostname
2) ssh-copy-id from host to pi, for convenient SSH
3) Set up software on the pi:
passwd
sudo apt update; sudo apt dist-upgrade
sudo apt install vim git screen htop rpi-update
sudo apt autoremove
sudo systemctl set-default multi-user.target # don't start X windows on boot
sudo BRANCH=next rpi-update
sudo reboot
4) Update bluez
sudo apt install libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz
tar -xf bluez-5.50.tar.xz`
cd bluez-5.50/
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental
make -j4
sudo make install
sudo cp /etc/dbus-1/system.d/bluetooth.conf /etc/dbus-1/system.d/bluetooth.conf.bak, then edit:
add to root: <allow send_interface="org.bluez.ThermometerWatcher1"/><allow send_interface="org.bluez.HeartRateWatcher1"/><allow send_interface="org.bluez.CyclingSpeedWatcher1"/>
add new child of busconfig: <policy group="bluetooth"><allow send_destination="org.bluez"/></policy>
5) Get bluetooth working
sudo adduser pi bluetooth
sudo reboot
bluetoothctl: scan on
bluetoothctl: trust 04:52:C7:5A:3B:A1
bluetoothctl: connect 04:52:C7:5A:3B:A1
aplay -D bluealsa:HCI=hci0,DEV=04:52:C7:5A:3B:A1,PROFILE=a2dp /usr/share/sounds/alsa/Front_Center.wav # test it works at all
6) Get bluetooth working without specifying the device by creating the following /etc/asound.conf file:
pcm.bose {
type plug
slave {
pcm {
type bluealsa
interface hci0
device 04:52:C7:5A:3B:A1
profile "a2dp"
}
}
hint {
show on
description "Bose speaker"
}
}
pcm.!default {
type plug
slave.pcm "bose"
}
ctl.!default {
type hw
card 0
}
For reference and credit, this is based on information from the following three sources:
link
link
link
And in reply to #Parthiban's comment above, here is the dbus-monitor output from the now-working system:
signal time=1541964336.104905 sender=org.freedesktop.DBus -> destination=:1.1 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.1"
signal time=1541964336.105032 sender=org.freedesktop.DBus -> destination=:1.1 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
string ":1.1"
method call time=1541964336.106756 sender=:1.0 -> destination=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RequestName
string "org.freedesktop.systemd1"
uint32 7
signal time=1541964336.106880 sender=org.freedesktop.DBus -> destination=(null destination) serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged
string "org.freedesktop.systemd1"
string ""
string ":1.0"
signal time=1541964336.107024 sender=org.freedesktop.DBus -> destination=:1.0 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string "org.freedesktop.systemd1"
method return time=1541964336.107096 sender=org.freedesktop.DBus -> destination=:1.0 serial=5 reply_serial=3
uint32 1
method call time=1541964336.108116 sender=:1.0 -> destination=org.freedesktop.DBus serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=ListNames
method return time=1541964336.108179 sender=org.freedesktop.DBus -> destination=:1.0 serial=6 reply_serial=4
array [
string "org.freedesktop.DBus"
string "org.freedesktop.systemd1"
string ":1.0"
]
I use a board running with Linux 3.0.8.
I follow the instructions from Documentation/input/rotary-encoder.txt and call the following in driver module:
platform_device_register(&rotary_encoder_device);
The kernel prints the following when boots up:
[5.629682] input: rotary-encoder as /devices/platform/rotary-encoder.0/input/input1
and I can get this:
# ls /sys/devices/platform/rotary-encoder.0/input/input1/
capabilities id name properties uevent
device modalias phys subsystem uniq
However there is no device node /dev/input/eventN created.
How to fix this? Thanks for any help.