Forum

Serial_open error d...
 
Notifications
Clear all

[Solved] Serial_open error during UART control from Raspberry Pi

7 Posts
2 Users
0 Likes
203 Views
Forum 1
(@mrcube3)
Active Member
Joined: 8 months ago
Posts: 5
Topic starter  

Dear Solo Team,

 

I am trying to implement joystick control of a BLDC motor using the SOLO Uno v.2.

My setup follows the tutorial https://www.solomotorcontrollers.com/blog/speed-controlling-bldc-raspberry-pi-hall-sensors/

The Piano Switch PIN NO# 5 is down. 

My code is attached below.

 

The issue: after running the code I receive the following error:

2023-02-06 23:33:55, 784 - SoloPy - ERROR - serial_open: Exception during the serial inizialisation

2023-02-06 23:33:55, 786 - SoloPy - INFO - Serial status not ready

The error continues cycling through the code

import SoloPy as solo
import sys
import pygame
from time import sleep
from pygame.constants import JOYBUTTONDOWN

#Define the motor settings
currentlimit = 8
pwmfrequency = 20
polecount = 8

#Define PID settings for motor controller
kp = 0.5
ki = 0.001

# Initialize the SOLO object 
mySolo = solo.SoloMotorControllerUart("/dev/ttyS0", 0, solo.UART_BAUD_RATE.RATE_937500)

# wait here till communication is established
while mySolo.serial_is_working() == False:
    sleep(1)
print("Communication Established successfully!")

# Initial Configurations
mySolo.set_command_mode(solo.COMMAND_MODE.DIGITAL)
mySolo.set_motor_type(solo.MOTOR_TYPE.BLDC_PMSM)
mySolo.set_output_pwm_frequency_khz(pwmfrequency)
mySolo.set_current_limit(currentlimit)

# run the motor identification
# run ID. always after selecting the Motor Type!
print("\n Identifying the Motor")
mySolo.motor_parameters_identification(solo.ACTION.START)
# wait at least for 2sec till ID. is done
sleep(3)

# Speed Controller Tunings
mySolo.set_speed_controller_kp(kp)
mySolo.set_speed_controller_ki(ki)
# Initial Configurations end

pygame.init()

joysticks = []
for i in range(0, pygame.joystick.get_count()):
    joysticks.append(pygame.joystick.Joystick(i))
    joysticks[-1].init()
    
# Print out the name of the controller
print(pygame.joystick.Joystick(0).get_name())
print(pygame.joystick.Joystick(0).get_numbuttons(), 'buttons available on the controller')
print(pygame.joystick.Joystick(0).get_numaxes(), 'axes available on the controller')

# Xbox Button Numbers:
# Button 0 - A
# Button 1 - B
# Button 2 - X
# Button 3 -
# Button 4 - Y
# Button 5 - RB
# Button 6 - View
# Button 7 - Menu
# Button 8 - XBox button
# Button 9 - LSB
# Button 10 - RSB
# Button 11 - 

# Main Loop
while True or KeyboardInterrupt:

    # Check for joystick events
    for event in pygame.event.get():
        if event.type ==JOYBUTTONDOWN:
            if event.button == 0:
                print("button 0 down")
            if event.button == 1:
                print("button 1 down")
            if event.button == 2:
                print("button 2 down")
            if event.button == 3:
                print("button 4 down")
            if event.button == 5:
                print("Braking...")
                #mySolo.set_speed_reference(0)
                sleep(5)
            if event.button == 6:
                print("button 6 down")
            if event.button == 7:
                print("button 7 down")
            if event.button == 8:
                print("button 8 down")
            if event.button == 9:
                print("button 9 down")
            if event.button == 10:
                print("button 10 down")
            if event.button == 11:
                print("button 11 down")

# Xbox Joystick Axis:
# Axis 0 up down, down value is -1, up value is 1
# Axis 1 Left, Right, Left value is: -1, right value is 1
# center is always 0

        if event.type == pygame.JOYAXISMOTION:
            if event.axis < 2: # Left stick
                if event.axis == 0: # left/right
                    if event.value < -0.5:
                        print("left")
                    #motor_speed = event.value * -1
                    #print(f"motor_speed: {motor_speed}")
                    #explorerhat.motor.one.backwards()
                    #explorerhat.motor.two.forwards()
                        sleep(0.01)
                    #explorerhat.motor.one.stop()
                    #explorerhat.motor.two.stop()
                    if event.value > 0.5:
                        print("right")                        
                    #explorerhat.motor.one.forwards()
                    #explorerhat.motor.two.backwards()
                        sleep(0.01)
                    #explorerhat.motor.one.stop()
                    #explorerhat.motor.two.stop()
                if event.axis == 1: # up/down
                    if event.value < -0.5:
                        print("up")
                    #explorerhat.motor.one.forwards()
                    #explorerhat.motor.two.forwards()
                        mySolo.set_motor_direction(solo.DIRECTION.CLOCKWISE)
                        mySolo.set_speed_reference(2000)
                        print("Actual Motor Iq: "+ str(mySolo.get_quadrature_current_iq_feedback()))
                        print("Motor Speed: " + str(mySolo.get_speed_feedback()))
                        sleep(0.25)
                    #explorerhat.motor.one.stop()
                    #explorerhat.motor.two.stop()
                        
                    if event.value > 0.5:
                        print("down")
                    #explorerhat.motor.one.backwards()
                    #explorerhat.motor.two.backwards()
                        mySolo.set_motor_direction(solo.DIRECTION.COUNTERCLOCKWISE)
                        mySolo.set_speed_reference(2000)
                        print("Actual Motor Iq: "+ str(mySolo.get_quadrature_current_iq_feedback()))
                        print("Motor Speed: " + str(mySolo.get_speed_feedback()))
                        sleep(0.25)
                        

   
SOLO_Francesco
(@solo_francesco)
Chief Member
Joined: 2 years ago
Posts: 27
 

1) check that you are using the latest version of SoloPy (3.0.0)

2) check with motion terminal that you are able to connect to your device and note down the port name (usually should be ttyACM0 or similar) ,

3) disconnect the device from motion terminal after the successful test

4) once the port name is clear, in your code replace the "/dev/ttyS0" to the correct name "/dev/ttyACM0" (or similar)   

 

I think this step will probably solve a wide range of possibility, we will also release a list of new examples for Ubuntu user to highlight the difference in port name vs Raspberry Pi.

Let me know if this steps solve your specific case.  


   
Forum 1
(@mrcube3)
Active Member
Joined: 8 months ago
Posts: 5
Topic starter  

Hello,

Unfortunately this didn't help. My SoloPy is indeed 3.0.0.

I noted down the serial port name and changed it to "/dev/ttyACM0" but I still have the same error...

Also the error persists if I run the code with

mySolo = solo.SoloMotorControllerUart()

, like in the example.

 

 


   
Forum 1
(@mrcube3)
Active Member
Joined: 8 months ago
Posts: 5
Topic starter  

Update: changing the port name to "/dev/ttyAMA0" helped but only partially. The code is now getting stuck on  "SoloPy - INFO - serial_open: success". It keeps reiterating and motor does not get identified. 

I also ran the code from SoloPy/BLDC_Speed_Control_HALL_based.py at main · Solo-FL/SoloPy (github.com) just to be sure but it gave the same result. Changing the baud rate did not help.

 

image

 

With kind regards,

Andre


   
SOLO_Francesco
(@solo_francesco)
Chief Member
Joined: 2 years ago
Posts: 27
 

@mrcube3 

this is a good progress, can you ensure your Device Address is set to 0? You can check it in the motion terminal (uart rate have to be aligned between your python code and device too).

For this test you can use this code (with correct SoloMotorControllerUart params for your setting)

import SoloPy as solo
import time

# instanciate a SOLO object:
mySolo = solo.SoloMotorControllerUart("/dev/ttyAMA0", 0, solo.UART_BAUD_RATE.RATE_937500)

# wait here till communication is established
print("Trying to Connect To SOLO:")
communication_is_working = False
while communication_is_working is False:
    time.sleep(1)
    communication_is_working, error = mySolo.communication_is_working()
print("Communication Established succuessfully!")
print("Program ended")
you can reach the end of the program or you are block inside the loop?
 
At this point the problem you are having look more related to the configuration on your OS:
- have a check of Readme SoloPy under UART protocol with RASPBERRY PI Note this are supposing you are using the UART line of your Raspberry and ttyS0
- or Specific Raspberry Pi forum in order to go deep under your port situation (example Permission denied /dev/ttyAMA0) for example if you are using USB port
 
Let me know how is going with this test too

   
Forum 1
(@mrcube3)
Active Member
Joined: 8 months ago
Posts: 5
Topic starter  

Hello, 

Unfortunately this did not help either. I was able to verify that my device address is indeed 0. I set my baudrate to 115200.

I still have the same error, where the message is "SoloPy - INFO - serial_open: success" and it gets stuck within the while loop in the above code.

I tried with a different RPi but the error still persists.

I will keep looking on solutions from RPi forums.

 

With kind regards,

Andre

This post was modified 8 months ago by mrcube3

   
Forum 1
(@mrcube3)
Active Member
Joined: 8 months ago
Posts: 5
Topic starter  

Ok a good update - I managed to solve the issue by disabling the bluetooth on my RPi, by following this tutorial ("Notes for the Raspberry Pi 3 Model B, B+, 4 and Raspberry Pi Zero W" section): Using the serial port on Raspberry Pi (abelectronics.co.uk)

Now it works as intended!

 

Thank you for the help Francesco!


   
Share: