Ivan.L
Posts: 12
Joined: Thu Oct 17, 2013 4:07 pm

Need help controlling brushed ESC

Fri Oct 18, 2013 6:24 pm

Hi,

I have a problem trying to controll an ESC with raspberry pi and pi-blaster.
This is the link for the esc.http://www.yourrccars4you.com/rchobby/i ... P166-2.jpg
I can't find any documentation about this esc.
I tried this esc with an arduino.It does't work if you try .write , bit it works fine if i use .writemicroseconds.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Need help controlling brushed ESC

Fri Oct 18, 2013 7:55 pm

http://abyz.co.uk/rpi/pigpio/download.html

After installing

sudo pigpiod

pigs s 4 1500 # send 1500us pulse on gpio4

Does that work for a servo connected to gpio4 (P1-7, see http://elinux.org/Rpi_Low-level_peripherals )

You need to connect the servo ground to a Pi ground as well as the servo power supply ground.

Ivan.L
Posts: 12
Joined: Thu Oct 17, 2013 4:07 pm

Re: Need help controlling brushed ESC

Sat Oct 19, 2013 8:52 pm

Just tried "pigs s 4 1500" after installing pigpio, and the motor started beeping.
Tried playing with the last number, the beeps were changing or completely stopping.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Need help controlling brushed ESC

Sat Oct 19, 2013 9:06 pm

ESCs tend to have in-built protection to stop model planes flying off when the power is plugged in.

Try setting 2000 for a couple of seconds and then 1000 for a couple of seconds. It may then respond properly to the in-between values.

e.g.

pigs s 4 2000 # max ESC throttle
sleep 2
pigs s 4 1000 # min ESC throttle
sleep 2
pigs s 4 1500 # mid throttle

If you got it working with the Arduino just send the same initialisation pulses you used on that.

Ivan.L
Posts: 12
Joined: Thu Oct 17, 2013 4:07 pm

Re: Need help controlling brushed ESC

Sun Oct 20, 2013 3:03 pm

When I was trying the ESC with arduino, I didn't do any initializations. And I don't think in needs one, because this ESC is used in only RC cars.

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Need help controlling brushed ESC

Sun Oct 20, 2013 8:40 pm

Ivan.L wrote:When I was trying the ESC with arduino, I didn't do any initializations. And I don't think in needs one, because this ESC is used in only RC cars.
Most ESCs need some kind of initialisation - usually involving pushing the sticks to extremes, just so that the ESC knows what the Max and Min signals are for this particular Transmitter.

Most of the ones I own require you to switch on the ESC in the "zero" position, then they beep, then you need to push the stick to Max and back to zero again. Then they beep again, and after that, the ESC is calibrated and armed.

You will have to simulate this with software if your ESC is like the above. Some are adaptive and will learn on the fly.
Last edited by alexeames on Mon Oct 21, 2013 7:08 am, edited 1 time in total.
Alex Eames RasPi.TV, RasP.iO

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Need help controlling brushed ESC

Sun Oct 20, 2013 9:02 pm

I take it we're not talking about the key in the top left of a keyboard here...... :)
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Need help controlling brushed ESC

Sun Oct 20, 2013 9:06 pm

pluggy wrote:I take it we're not talking about the key in the top left of a keyboard here...... :)
http://en.wikipedia.org/wiki/Electronic_Speed_Control

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Need help controlling brushed ESC

Sun Oct 20, 2013 9:26 pm

The link says it all.

Thanks.

ESC is a bit of a minefield.

http://en.wikipedia.org/wiki/ESC
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Need help controlling brushed ESC

Mon Oct 21, 2013 7:10 am

pluggy wrote:The link says it all.

Thanks.

ESC is a bit of a minefield.

http://en.wikipedia.org/wiki/ESC
Yeah, but "brushed ESC" narrows it down quite a lot :lol:
I tend to vacuum my computer keyboards rather than brush them :D (YMMV)
Alex Eames RasPi.TV, RasP.iO

Ivan.L
Posts: 12
Joined: Thu Oct 17, 2013 4:07 pm

Re: Need help controlling brushed ESC

Mon Nov 04, 2013 7:19 pm

Ok guys, I don,t know what happened , but the motor started working when I typed pigs s 4 1500. :D
Now if I want to control the motor from python which command should I use?

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Need help controlling brushed ESC

Mon Nov 04, 2013 8:37 pm

Ivan.L wrote:Ok guys, I don,t know what happened , but the motor started working when I typed pigs s 4 1500. :D
Now if I want to control the motor from python which command should I use?
Using pigpio.

Save code in file py-servo.py

Code: Select all

#!/usr/bin/python

import socket
import struct
import time

# Macro        Cmd Function           P1      P2           Result
# =====        === ========           ==      ==           ======
# PI_CMD_MODES  0  Set Mode           gpio    mode         status
# PI_CMD_MODEG  1  Get Mode           gpio    -            mode
# PI_CMD_PUD    2  Set pull up/down   gpio    value        status
# PI_CMD_READ   3  Read               gpio    -            level
# PI_CMD_WRITE  4  Write              ugpio   level        status
# PI_CMD_PWM    5  PWM                ugpio   dutycycle    status
# PI_CMD_PRS    6  Set PWM range      ugpio   range        real_range
# PI_CMD_PFS    7  Set PWM frequency  ugpio   frequency    set_frequency
# PI_CMD_SERVO  8  Servo              ugpio   pulsewidth   status
# PI_CMD_WDOG   9  Set watchdog       ugpio   timeout      status
# PI_CMD_BR1   10  Read bank 1        -       -            levels
# PI_CMD_BR2   11  Read bank 2        -       -            levels
# PI_CMD_BC1   12  Clear bank 1       bits    -            0
# PI_CMD_BC2   13  Clear bank 2       bits    -            0
# PI_CMD_BS1   14  Set bank 1         bits    -            0
# PI_CMD_BS2   15  Set bank 2         bits    -            0
# PI_CMD_TICK  16  Tick               -       -            tick
# PI_CMD_HWVER 17  H/W Ver.           -       -            revision
# PI_CMD_NO    18  Notify open        -       -            handle
# PI_CMD_NB    19  Notify begin       handle  bits         status
# PI_CMD_NP    20  Notify pause       handle  -            status
# PI_CMD_NC    21  Notify close       handle  -            status
# PI_CMD_PRG   22  Get PWM range      ugpio   -            range
# PI_CMD_PFG   23  Get PWM frequency  ugpio   -            frequency
# PI_CMD_PRRG  24  Get PWM real range ugpio   -            real_range

def pigpioCmd(s, cmd, p1, p2):
   s.send(struct.pack('IIII', cmd, p1, p2, 0))
   x, y, z, res = struct.unpack('IIII', s.recv(16))
   return res
  
def servo(pin, pulseLen):
   return pigpioCmd(s, 8, pin, pulseLen);

def pwm(pin, dutyCycle):
   return pigpioCmd(s, 5, pin, dutyCycle);

HOST = ''    # The remote host name, use '' if on local machine
PORT = 8888  # default pigpio port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((HOST, PORT))

for pulse in xrange(1400, 1600):
   servo(4, pulse)
   time.sleep(0.2)

s.close()
chmod +x py-servo.py

sudo pigpiod # start deamon

./py-servo.py

Return to “General discussion”