Hi, I'm having a problem with the Elegoo Smart Robot Car. Following the instructions in this video:
(https://www.youtube.com/watch?v=j7p44vxyvdM), I get no response from the car when I send data to it. I can send a simple command in the Spyder interface,
import socket
import json
import sys
import time
import re
# Yes, I know thatt I'm not using time or re.
ip = "192.168.4.1"
port = 100
print('Connect to {0}:{1}'.format(ip, port))
car = socket.socket()
try:
car.connect((ip, port))
except:
print('Error: ', sys.exc_info()[0])
sys.exit()
print('Connected!')
print('Receive from {0}:{1}'.format(ip, port))
def recieve():
try:
data = car.recv(1024).decode()
except:
print('Error: ', sys.exc_info()[0])
sys.exit()
print('Received: ', data)
msg = { "H": 1 , "N": 5 , "D1": 1 , "D2" : 30}
jsonmsg = json.dumps(msg)
off = [0.007, 0.022, 0.091, 0.012, -0.011, -0.05]
try:
# Send the car a message
car.send(jsonmsg.encode())
print('Sent: ' + jsonmsg)
except:
print('Error: ', sys.exc_info()[0])
sys.exit()
recieve()
And I get nothing from the car. What's supposed to happen is the car should rotate a servo motor, it does not rotate the servo motor. It's supposed to send back feedback, does not send feedback. No error messages, nothing. Please help!
If useful, I'm running a Windows 11 Pro.
Tell me if you need more code, the robot's source code, etc.
Those kits can be built and programmed from start to finish with no problems, but when there is a problem, start with testing each device, then add and test, repeat...
About minute 7 of the video in Post #1, things get out-of-hand, by re-writing library files, and more in-depth figuring out... Maybe write to Elegoo technical support.
The code is stuck in an infinite while loop, looking for information that does not exist, since there cannot be an response for an invalid/unexisting send.
I triple checked the video, his settings, and stuff. I'll rewatch the video, but for now, I can't find the issue
More information: In Arduino IDE, I can use the Serial monitor to send commands via usb. For example: {"H":1, "N": 5, "D1": 1, "D2": 30}. H is the command identifier, so its identifier is 1. N is the command type, and five corresponds to rotating the servo. D1 is the first parameter, the servo type in this case. My servo type is one. D2 parameter 2, the angle to rotate the servo at, in this case, which is 30. Sending this code rotates the servo 30 degrees.
But, running the same command via sockets via Spyder python console doesn't get any reply or response.
The input in the serial monitor, and the response from the robot's code:
Cuz it turns when I use arduino IDE via usb but not over sockets
Note: I'm really grateful for you to help me with this. I'm sorry if I get on your nerves or anything, but last post I made went completely unreplied to and I had to figure it out on my own
Without seeing the receiver code, kind of hard to tell..
Wonder though, could just be waiting for an ending newline..
Your serial terminal adds one for you on each string you type and send..
Try to add a newline to your python, sorry, can't help with that..