User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Which Software Route - RPi / Arduino Web Controlled Robot

Wed Jul 01, 2015 3:53 pm

Ok;

I have posted several posts over the past week getting advice and making some progress with my latest venture, what I would like now is a little steer regarding which software / hardware route to take next.

Aim - To build a mobile robot that can be controlled over the web (LAN / WAN). Onboard webcam to provide video streamed to a web page / control panel to drive the robot. The aim is for the robot to be able to have an autonomous mode to be able to navigate around by itself when not being manually controlled.

So far I have Apache2 running on the bot serving a web page created using Bootstrap containing four buttons (Fwd, Back, Left, Right). The web page calls CGI Python scripts on the Pi which control the motors attached to an Arduino Nano ATMega328 / L298N Motor Driver Board. The interface software is from a blog which is a couple of years old, it works but this method is painfully slow and although I could drive each individual motor I am having trouble tying it all together i.e. I can get both motors to go fwd but only one will go back.

What I need to do now is work out a better software (and possibly) hardware solution.

I was going to pursue wsgi and attempt to re-write the Arduino and Pi Slave Master scripts but I have just come across some information on Tornado and Websockets along with some Arduino and Python code.

What would be the best solution Apache / wsgi or Tornado and Websockets?
Is Tornado a Webserver or will I need to run Apache and Tornado?

Please excuse my lack of understanding?
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Jul 01, 2015 4:00 pm

I'll be watching this thread for the solution to the best implementation of the web control.

I don't see that the arduino is adding anything except for lag to your control of the robot, you can easily control a L298N from the Pi alone, including speed control if desired (and easily control your motors).
Doug.
Building Management Systems Engineer.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Jul 01, 2015 4:06 pm

I found a video on Youtube that apparently uses an RPi connected to an Arduino receiving commands over I2C, the 'flash to bang' between pressing a button on the web page and the LED lighting up seems pretty slick?

Here's the youtube video:
https://www.youtube.com/watch?v=SHbX_4zymfQ

Here's the Arduino / RPi code link on Github which uses Tornado:

https://github.com/TinHead/TTBN-Alpha

And here's the LMR link, nice bot and it runs on a Pi:

http://letsmakerobots.com/robot/project/ttbn-alpha

TBH I may end up ditching the Arduino which if you follow the LMR link on the Youtube page, the posters states in the comments that the Arduino has now gone.

Still need to best web control solution either way.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Jul 01, 2015 8:25 pm

The arduino nano have the usb port on it . Simply connect the usb directly into the pi et use standard serial communication to control it.

But I will ditch the arduino since you don't need it.

I do have something similar with what you have and it is running on Pi A version.

I'm using webiopi which is a python web server that you could pass python function into it.

This is a post explaining the webinterface. (It's in french but the pyhon and web page are easy to figure out).
viewtopic.php?p=353089#p353089

A schematic of my robot
Image

It is more than two years old now. I only replace the Pi B with a Pi A.
Some of the components like the R/C servo controller could be removed and directly connected to the GPIO.

Image

A video before I implement the web interface.
https://dl.dropboxusercontent.com/u/488 ... botCar.mpg

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Sun Jul 05, 2015 7:13 pm

danjperron wrote:The arduino nano have the usb port on it . Simply connect the usb directly into the pi et use standard serial communication to control it.

But I will ditch the arduino since you don't need it.

I do have something similar with what you have and it is running on Pi A version.

I'm using webiopi which is a python web server that you could pass python function into it.

This is a post explaining the webinterface. (It's in french but the pyhon and web page are easy to figure out).
viewtopic.php?p=353089#p353089
Thanks very much for this - not had a chance to look in depth as I have been trying to get my head around solutions such as node.js / socket.io and tornado / python.

I think node.js is probably the best way to go but I really struggled finding examples along the lines of what I wanted to achieve and understand.
I have just spent a couple of days looking back over Tornado / Python Websockets and came across an interesting article on Python based serial console using websockets, I followed it and had some success :-)

Here is the article:

http://fabacademy.org/archives/2015/doc ... nsole.html

I have now successfully set up a USB (for the time being) serial connection between the Pi and my Arduino Nano. The Arduino is running a simple loop printing 'Hello Pi' to the serial port and the Pi is receiving this data and printing it to a console on a web page. Here is a screen shot of it in use:

Image

Next I will attempt to modify the code to see if it will work over I2C.

Whether its I2C or USB I then need to modify the existing page to control LEDs (in lieu of motors) then find out how to modify the code to activate motors via button pushes on a web page control panel.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Sun Jul 05, 2015 7:31 pm

There was another post about moving a robot using the web.
viewtopic.php?p=784173#p784173

I post detail method on how to implement webiopi with a simple html form.

I use websocket with my RF24 arduino sensor on battery with the help of MQTT to read all my IOT sensors.
The webpage use web socket to get the sensor information. So websocket is good way to communicate.

B.T.W. webiopi is a python webserver. You are able to create your own python function and implement a javascript handshake with them. This is quite nice . I do have some webiopi chitchat to read or set I/O this way.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Sun Jul 05, 2015 7:45 pm

danjperron wrote:There was another post about moving a robot using the web.
viewtopic.php?p=784173#p784173

I post detail method on how to implement webiopi with a simple html form.

I use websocket with my RF24 arduino sensor on battery with the help of MQTT to read all my IOT sensors.
The webpage use web socket to get the sensor information. So websocket is good way to communicate.

B.T.W. webiopi is a python webserver. You are able to create your own python function and implement a javascript handshake with them. This is quite nice . I do have some webiopi chitchat to read or set I/O this way.
danjperron;

Just had a good read through your responses in the link you gave regarding the use of webiopi, this looks like a very good solution :-)

Question - Clearly webiopi will allow me to communicate and control a Pi based Robot but do you believe that I would be able to use webiopi with python websockets and a serial interface to an Arduino?
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Sun Jul 05, 2015 8:58 pm

do you believe that I would be able to use webiopi with python websockets and a serial interface to an Arduino?
I don't see why not! python have code for serial and socket connection.

This is how I use socket connection with my RF24 sensor
viewtopic.php?p=742704#p742704

And this is my python code I used for my robot. I do have a little more than 4 buttons. In the code I do have a sparkfun serial R/C servo controller which is connected directly to /dev/ttyAMA0.

Code: Select all

#!/usr/bin/env python
from time import sleep
import webiopi
import RPi.GPIO as GPIO
from select import select   
import serial
import ossaudiodev
import wave
from threading import Thread

out = serial.Serial('/dev/ttyAMA0',38400)


CamX = int(3000)
CamY = int(3000)

#set io pin

EnA = 11
EnB = 15
Out1 = 24
Out2 = 21
Out3 = 19
Out4 = 23

GPIO.setmode(GPIO.BOARD)




def Forward():
   GPIO.output(Out1,True)
   GPIO.output(Out3,True)
   GPIO.output(Out2,False)
   GPIO.output(Out4,False)
   GPIO.output(EnA,True)
   GPIO.output(EnB,True)

def Stop():
   GPIO.output(Out1,False)
   GPIO.output(Out3,False)
   GPIO.output(Out2,False)
   GPIO.output(Out4,False)
   GPIO.output(EnA,True)
   GPIO.output(EnB,True)

def Standby():
   GPIO.output(Out1,False)
   GPIO.output(Out3,False)
   GPIO.output(Out2,False)
   GPIO.output(Out4,False)
   GPIO.output(EnA,False)
   GPIO.output(EnB,False)

def Reverse():
   GPIO.output(Out2,True)
   GPIO.output(Out4,True)
   GPIO.output(Out1,False)
   GPIO.output(Out3,False)
   GPIO.output(EnA,True)
   GPIO.output(EnB,True)

def TurnRight():
   GPIO.output(Out1,True)
   GPIO.output(Out3,False)
   GPIO.output(Out2,False)
   GPIO.output(Out4,True)
   GPIO.output(EnA,True)
   GPIO.output(EnB,True)

def TurnLeft():
   GPIO.output(Out1,False)
   GPIO.output(Out3,True)
   GPIO.output(Out2,True)
   GPIO.output(Out4,False)
   GPIO.output(EnA,True)
   GPIO.output(EnB,True)


def ServoSpeed(id , speed):
 out.write('\x80\x01\x01' + chr(id) + chr(speed))
 print("Servo ",id,"speed = ",id,speed)

def ServoSleep(id):
 out.write('\x80\x01\x00' + chr(id) + chr(15))
 print("Servo ",id," to sleep")

def Servo( id , ServoPosition):
 out.write('\x80\x01\x04' + chr(id) + chr(ServoPosition >>7) + chr(ServoPosition & 0x7f))
 print("Servo ",id," = ",ServoPosition)
def CloseJaw():
 Servo(2,4400)

def OpenJaw():
 Servo(2,1000)

def play(filename):
  print "opening file"
  sound_file = wave.open(filename,'rb')

  print "getting parameters"
  (nc, sw, fr, nf, comptype, compname) = sound_file.getparams()

  print "parameters were",  (nc, sw, fr, nf, comptype, compname)
  print "opening audio"
  sound = ossaudiodev.open('w')

  print "setting parameters"
  sound.setparameters(ossaudiodev.AFMT_S16_NE, nc, fr)

  print "readframes"
  data = sound_file.readframes(nf)

  print "closing file"
  sound_file.close()

  print "writing data"
  sound.write(data)

  # Never gets here, freezes on the previous line.
  print "closing sound device"
  sound.close()




   
def Play1():
   thread = Thread(target = play, args=("ialert.wav",))
   thread.start()

def Play2():
   thread = Thread(target = play, args=("tos-redalert.wav",))
   thread.start()

def Play3():
   thread = Thread(target = play, args=("s3.wav",))
   thread.start()

def Play4():
   thread = Thread(target = play, args=("s4.wav",))
   thread.start()

def Play5():
   thread = Thread(target = play, args=("s5.wav",))
   thread.start()

def Play6():
   thread = Thread(target = play, args=("s6.wav",))
   thread.start()

def Play7():
   thread = Thread(target = play, args=("s7.wav",))
   thread.start()

def Play8():
   thread = Thread(target = play, args=("s8.wav",))
   thread.start()

def Play9():
   thread = Thread(target = play , args=("s9.wav",))
   thread.start()


#============ MAIN ==============
homeX = 2800
homeY = 3000
CamX = homeX
CamY = homeY

def CameraSet():
   global CamX
   global CamY
   Servo(0, CamX+70)
   Servo(1, CamY)

def CameraUp():
   global CamX
   global CamY
   CamY=CamY + 100
   if CamY > 3600:
      CamY = 3600
   CameraSet()

def CameraDown():
   global CamX
   global CamY
   CamY=CamY - 100
   if CamY < 2200:
      CamY = 2200
   CameraSet()

def CameraLeft():
   global CamX
   global CamY
   CamX = CamX - 200
   if CamX < 800:
      CamX = 800
   CameraSet()

def CameraRight():
   global CamX
   global CamY
   CamX = CamX + 200
   if CamX > 4800:
      CamX = 4800
   CameraSet()

def CameraHome():
   global CamX
   global CamY
   CamX = homeX
   CamY = homeY
   CameraSet()   

def CameraStop():
   CameraSet()


CameraSet()
ServoSpeed(0,32)
ServoSpeed(1,32)

GPIO.setmode(GPIO.BOARD)

# set enable a as output
GPIO.setup(EnA,GPIO.OUT)
GPIO.output(EnA, False)

#set enable b as output

GPIO.setup(EnB,GPIO.OUT)
GPIO.output(EnB, False)


#set enable out 1,2,3 and 4  as output

GPIO.setup(Out1,GPIO.OUT)
GPIO.setup(Out2,GPIO.OUT)
GPIO.setup(Out3,GPIO.OUT)
GPIO.setup(Out4,GPIO.OUT)


GPIO.output(Out1,False)
GPIO.output(Out2,False)
GPIO.output(Out3,False)
GPIO.output(Out4,False)


server = webiopi.Server(
            port=8000,
            login="robot",
            password="r2d2")


server.addMacro(Forward)
server.addMacro(Stop)
server.addMacro(Reverse)
server.addMacro(TurnRight)
server.addMacro(TurnLeft)
server.addMacro(OpenJaw)
server.addMacro(CloseJaw)
server.addMacro(CameraHome)
server.addMacro(CameraUp)
server.addMacro(CameraDown)
server.addMacro(CameraLeft)
server.addMacro(CameraRight)
server.addMacro(CameraStop)
server.addMacro(Play1)
server.addMacro(Play2)
server.addMacro(Play3)
server.addMacro(Play4)
server.addMacro(Play5)
server.addMacro(Play6)
server.addMacro(Play7)
server.addMacro(Play8)
server.addMacro(Play9)


webiopi.runLoop()
server.stop()
I will need to update the code but if you look into it you will see the serial connection. I also play some audio sound with it.

The main webpage use frame, one for the mjpeg_streamer and one for the control.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Mon Jul 06, 2015 2:23 pm

Just found this info on the Pi Store ref WEBIOPI:

http://store.raspberrypi.com/projects/webiopi

Looks promising :-)
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Mon Jul 06, 2015 8:08 pm

Well at first trying to customise the scripts with my limited knowledge I had some issues, but then when I went back over it using the default scripts with an LED connected to one of the defined pins on the Pi I successfully iluminated an LED.

HALLELLUYA!!!

Now to try it over I2C serial :-(
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Mon Jul 06, 2015 8:12 pm

Maybe post your python and webpage script. I will look what was wrong with it.

Daniel

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Jul 15, 2015 12:02 am

I have been messing around with some examples using webiopi and pigpio and have had some limited success.
I have now written a python program and a corresponding .html file.

For some reason I now keep getting a socket.error [Errno 98] Address already in use!!

Can you have a look at them see what I am doing wrong, also where should they be filed?

I think I have Apache2 running as well?

html: /usr/share/webiopi/htdocs/

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
<title>Hammerstein_Mobile_Control_Panel</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">

   function cam_pan_left() {
        webiopi().callMacro("cam_pan_left");
   }

   function cam_pan_right() {
       webiopi().callMacro("cam_pan_right");
    }

   function cam_pan_centre() {
       webiopi().callMacro("cam_pan_centre");
    }

   function cam_tilt_up() {
       webiopi().callMacro("cam_tilt_up");
    }

   function cam_tilt_down() {
       webiopi().callMacro("cam_tilt_down");
    }

   function cam_tilt_centre() {
       webiopi().callMacro("cam_tilt_centre");
    }

   function cam_stop() {
       webiopi().callMacro("cam_stop");
    }

   webiopi().reday(init);

</script>


<style type="text/css"> 
.myButton {
   -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
   -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
   box-shadow:inset 0px 1px 0px 0px #ffffff;
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #f6f6f6));
   background:-moz-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-webkit-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-o-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-ms-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
   background-color:#ffffff;
   -moz-border-radius:6px;
   -webkit-border-radius:6px;
   border-radius:6px;
   border:1px solid #dcdcdc;
   display:inline-block;
   cursor:pointer;
   color:#666666;
   font-family:Arial;
   font-size:15px;
   font-weight:bold;
   padding:6px 24px;
   text-decoration:none;
   text-shadow:0px 1px 0px #ffffff;
        width: 130px;
        height:30px;
        margin:1px;
}
.myButton:hover {
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f6f6f6), color-stop(1, #ffffff));
   background:-moz-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-webkit-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-o-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-ms-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:linear-gradient(to bottom, #f6f6f6 5%, #ffffff 100%);
   background-color:#f6f6f6;
        padding:6px 24px;
}
.myButton:active {
   color:#ff0000;
        position:relative;
   top:1px;
        padding:6px 24px;
}

</style>

</head>
<body>
<center><h3>Hammerstein Control Panel</h3></center><br>


<center>
<table>
<tr><td colspan=3 align="center"><button class="myButton" onmousedown="cam_tilt_up()" onmouseup="cam_stop()">Tilt Up</but$
<tr><td><button class="myButton" type="button" onmousedown="cam_pan_left()" onmouseup="cam_stop()">Pan Left</button></td>
<td><button class="myButton" type="button" onclick="cam_stop()">Cam Stop</button></td>
<td><button class="myButton" type="button" onmousedown="cam_pan_right()" onmouseup="cam_stop()">Pan Right</button></td></$
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="cam_tilt_down()" onmouseup="cam_stop$
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="LED_On()" onmouseup="Stop()">LED_On<$
</table>
</center>


</body>
</html>
python: /home/pi/WebIOPi-0.7.1/my_projects

Code: Select all

# Prior to running this program you must start the pigpio daemon by
# entering 'sudo pigpiod' at the command prompt
# To start webiopi enter 'sudo webiopi -d -c /etc/webiopi/config' at the command prompt

#!/usr/bin/env python
import webiopi
import time
import pigpio
pi = pigpio.pi()

# Start the webiopi server
# server = webiopi.Server(port=8000, login="Hammerstein", password="Hammerstein"

# Define functions

def cam_pan_left():
        pi.set_servo_pulsewidth(23, 1100)
        time.sleep(1)
        pi.set_servo_pulsewidth(23, 0)

def cam_pan_right():
        pi.set_servo_pulsewidth(23, 1900)
        time.sleep(1)
        pi.set_servo_pulsewidth(23, 0)

def cam_pan_centre():
        pi.set_servo_pulsewidth(23, 1500)
        time.sleep(1)
        pi.set_servo_pulsewidth(23, 0)

def cam_tilt_up():
        pi.set_servo_pulsewidth(24, 1100)
        time.sleep(1)
        pi.set_servo_pulsewidth(24, 0)
        pi.stop()

def cam_tilt_down():
        pi.set_servo_pulsewidth(24, 1900)
        time.sleep(1)
        pi.set_servo_pulsewidth(24, 0)

def cam_tilt_centre():
        pi.set_servo_pulsewidth(24, 1500)
        time.sleep(1)
        pi.set_servo_pulsewidth(24, 0) 

# Start the webiopi server
server = webiopi.Server(port=8000, login="", password="")

# Register the macros

server.addMacro(cam_pan_left)
server.addMacro(cam_pan_right)
server.addMacro(cam_pan_centre)
server.addMacro(cam_tilt_up)
server.addMacro(cam_tilt_down)
server.addMacro(cam_tilt_centre)
server.addMacro(cam_stop)

# Run default loop
# webiopi.runloop()

# Cleanly stop server
server.stop()
pi.stop()
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Jul 15, 2015 1:19 am

Ok you are using pigpio also.

pigpiod need to run before webiopi.

1- Stop webiopi
2- Start pigpiod
3- Start webiopi


You should create a service with pigpiod and make it start before webiopi.


B.T.W. webiopi start when you power the Pi. If you don't want that disable it

Code: Select all

sudo chmod -x /etc/init.d/webiopi
and reboot or

Code: Select all

sudo service webiopi stop

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Jul 16, 2015 12:39 am

Dan;

Many thanks for your continued help.

Whenever I ran the program

I got the following error:
File "/home/pi/WebIOPi-0.7.1/my_projects/Hammerstein.py", line 72, in <module>
webiopi.runloop()
AttributeError: 'module' object has no attribute 'runloop'

So I commented out webiopi.runloop() and Stop() from the bottom of my py script (what should they do?)
Once I did this and ran webiopi again I was able to control the servos YESSSS :-)

Whenever I first run webiopi I can see the following in Google Chrome Element Inspector :
Uncaught ReferenceError: $ is not defined

And whenever I operate the servo by pressing a button I get the following error also in Google Chrome Element Inspector
POST http://192.168.2.2:8000/macros/cam_pan_left/ 500 (Internal Server Error)

Do I need to worry?

Here is my amended python:

Code: Select all

# Prior to running this program you must start the pigpio daemon by
# entering 'sudo pigpiod' at the command prompt
# To start webiopi enter 'sudo webiopi -d -c /etc/webiopi/config' at the command prompt

#!/usr/bin/env python
import webiopi
from time import sleep
import pigpio
pi = pigpio.pi()

# Start the webiopi server
# server = webiopi.Server(port=8000, login="UserName", password="Password"

# Define functions

#@webiopi.macro
def cam_pan_left():
    pi.set_servo_pulsewidth(23, 1900)
    time.sleep(1)
    pi.set_servo_pulsewidth(23, 0)

#@webiopi.macro
def cam_pan_right():
    pi.set_servo_pulsewidth(23, 1100) 
    time.sleep(1)
    pi.set_servo_pulsewidth(23, 0)

#@webiopi.macro
def cam_pan_centre():
    pi.set_servo_pulsewidth(23, 1500)
    time.sleep(1)	
    pi.set_servo_pulsewidth(23, 0)

#@webiopi.macro
def cam_tilt_up():
    pi.set_servo_pulsewidth(24, 1100)	
    time.sleep(1)
    pi.set_servo_pulsewidth(24, 0)

#@webiopi.macro
def cam_tilt_down():
    pi.set_servo_pulsewidth(24, 1900)	
    time.sleep(1)	
    pi.set_servo_pulsewidth(24, 0)

#@webiopi.macro	
def cam_tilt_centre():
    pi.set_servo_pulsewidth(24, 1500)
    time.sleep(1)
    pi.set_servo_pulsewidth(24, 0)

#@webiopi.macro
def cam_stop():
    pi.set_servo_pulsewidth(23, 0)
    pi.set_servo_pulsewidth(24, 0)


# Start the webiopi server
server = webiopi.Server(port=8000, login="Hammerstein", password="Hammerstein")

# Register the macros

server.addMacro(cam_pan_left)
server.addMacro(cam_pan_right)
server.addMacro(cam_pan_centre)
server.addMacro(cam_tilt_up)
server.addMacro(cam_tilt_down)
server.addMacro(cam_tilt_centre)
server.addMacro(cam_stop)

# Run default loop
#webiopi.runloop()

# Cleanly stop server
#server.stop()

And here is my html:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> 
<title>Hammerstein_Mobile_Control_Panel</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">

   function cam_pan_left() {
   	webiopi().callMacro("cam_pan_left");
   }
   
   function cam_pan_right() {
       webiopi().callMacro("cam_pan_right");
    }

   function cam_pan_centre() {
       webiopi().callMacro("cam_pan_centre");
    }

   function cam_tilt_up() {
       webiopi().callMacro("cam_tilt_up");
    }

   function cam_tilt_down() {
       webiopi().callMacro("cam_tilt_down");
    }

   function cam_tilt_centre() {
       webiopi().callMacro("cam_tilt_centre");
    }

   function cam_stop() {
       webiopi().callMacro("cam_stop");
    }

</script>


<style type="text/css">

.myButton {
   -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
   -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
   box-shadow:inset 0px 1px 0px 0px #ffffff;
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #f6f6f6));
   background:-moz-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-webkit-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-o-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-ms-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
   background-color:#ffffff;
   -moz-border-radius:6px;
   -webkit-border-radius:6px;
   border-radius:6px;
   border:1px solid #dcdcdc;
   display:inline-block;
   cursor:pointer;
   color:#666666;
   font-family:Arial;
   font-size:15px;
   font-weight:bold;
   padding:6px 24px;
   text-decoration:none;
   text-shadow:0px 1px 0px #ffffff;
        width: 130px;
        height:30px;
        margin:1px;
}
.myButton:hover {
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f6f6f6), color-stop(1, #ffffff));
   background:-moz-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-webkit-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-o-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-ms-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:linear-gradient(to bottom, #f6f6f6 5%, #ffffff 100%);
   background-color:#f6f6f6;
        padding:6px 24px;
}
.myButton:active {
   color:#ff0000;
        position:relative;
   top:1px;
        padding:6px 24px;
}

</style>

</head>
<body>
<center><h3>Hammerstein Control Panel</h3></center><br>


<center>
<table>
<tr><td colspan=3 align="center"><button class="myButton" onmousedown="cam_tilt_up()" onmouseup="cam_stop()">Tilt Up</button></td></tr>
<tr><td><button class="myButton" type="button" onmousedown="cam_pan_left()" onmouseup="cam_stop()">Pan Left</button></td>
<td><button class="myButton" type="button" onclick="cam_stop()">Cam Stop</button></td>
<td><button class="myButton" type="button" onmousedown="cam_pan_right()" onmouseup="cam_stop()">Pan Right</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="cam_tilt_down()" onmouseup="cam_stop()">Tilt Down</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="LED_On()" onmouseup="Stop()">LED_On</button></td></tr>
</table>
</center>


</body>
</html>
Last edited by JonnyAlpha on Tue Jul 21, 2015 5:01 pm, edited 1 time in total.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Jul 16, 2015 12:54 am

I did check my old code from my PI robot and I do have the two last lines than you remark.


but you have a typo it is webiopi.runLoop() upper case 'L'

Code: Select all

webiopi.runLoop()
server.stop()

I don't know about the error. maybe it is due to the missing webiopi.runLoop()

User avatar
mikronauts
Posts: 2794
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Jul 16, 2015 12:58 am

Since you were asking about hardware:

For chassis, I like:

2WD Magician - cheap, easy to use, can be driven with L293D, L9110S, L298N

2WD Rover 5 with encoders - bigger bots, more accurate (and cheaper than 4WD version) - I drive it with L298N

Boe-Bot chassis from Parallax - uses continuous rotation servos.

Wild Thumper 6WD - my magellan bot build to be :) - needs beefy motor driver, 3x6A stall current on each side

For controllers, I like:

http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
Good match for 2WD Magician

http://www.mikronauts.com/raspberry-pi/robopi/
Just add an appropriately sized motor driver :)

Mind you, it is not surprising I like those controllers - after all, I designed them :)

At the moment, I run autonomously 99% of the time, but use ssh to a Python shell at times for testing.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

danjperron
Posts: 3508
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Jul 16, 2015 11:31 am

@Mikronauts I gona do the opposite !

I think I will Update my robot and replace the PiA by a Pi B+. Also removing the sparkfun servo and use pigpio to control the servo exactly like JonnyAlpha. And I will replace the L298 driver by a CMOS TB6612. I have already the I.C. module from pololu. This way I could remove the USB hub. So it will be a strip version.

The battery pack I got is a USB 12000ma with an external 9V output. they don't do it anymore because I will have bought another one. I use the 9V to drive the motor but since it is 9V the L298 voltage drop has an impact on the power provide by the motors. Now the drop should be around 0.5V instead of ~2V.

B.T.W. When I don't use the robot it is always plug on the wall with the provided adapter and the Raspberry PI is always ON. This way I could run the robot remotely and check if my kids lock the door when they leave. It has enough power to keep the Pi running until I return home.

On the next update I think I will manage to salvage one of the Roomba base station and use it to charge the adapter. This way I won't have a adapter cable as tale when I moved the robot remotely. ;-)

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Jul 16, 2015 11:08 pm

danjperron wrote:I did check my old code from my PI robot and I do have the two last lines than you remark.


but you have a typo it is webiopi.runLoop() upper case 'L'

Code: Select all

webiopi.runLoop()
server.stop()

I don't know about the error. maybe it is due to the missing webiopi.runLoop()
Dan;

Sorry yes it was the typo, well spotted, both webiopi.runLoop() and server.stop() have been uncommented and everything is working perfectly.

Thank you very much

Now to investigate doing this over I2C and using an Arduino Nano to control the servos and motors?
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Tue Aug 04, 2015 9:14 pm

Ok as a follow up I have now successfully got my motors and servo for the sensor all running via i2c and WebIOPi. Had a little trouble with WebIOPi not liking smbus but then I upgraded smbus to Python 3 and all worked fine.

The only trouble I have now is controlling the length of time that the motors are on, at the moment they run for a full second but when turning that does not give a lot of control as the thing will spin 360 in that time.

If anyone can look at my code and let me know if more control is possible?
I may be able to play with the PWM but I don't think its making any difference but I am not sure why?

There is some redundant code in the Sketch that I have not cleaned up yet.

Here is the Python code:

Code: Select all

# Python programme for controlling Arduino Nano connected to a Raspberry Pi using i2c serial communication
# inspiration for the i2c element from Osar laing's Blog
# http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c
# Commands sent to Raspberry Pi over a web page using webiopi
# Prior to running this program you must start the pigpio daemon
# by either entering pigpiod at a command prompt or running it automatically at startup 
# as a CRON job
# If you recieve a module import error no module named smbus ensure version of smbus
# and WebIOPi Python match

#/usr/bin/env python

import webiopi # Import webiopi - software to communicate with a Rapsberry Pi over a web interface
import smbus as smbus
import time
import pigpio # pigpio is a custom module for controlling GPIO pins

pi = pigpio.pi #declare psuedo for pigpio commands

bus = smbus.SMBus(1) # For RPI version 1 use "bus = smbus.SMBus(0)"

# Setup i2C communication address (must be the same as address set on Arduino
address = 0x04

def writeNumber(value):
   	bus.write_byte(address, value)
	# bus.write_byte_data(address, 0, value)
   	return -1

def readNumber():
	number = bus.read_byte_data(address, 1)
	return number
		
#@webiopi.macro
def stop():
        number = 0
        writeNumber(number)
        time.sleep(1)
        
#@webiopi.macro
def forward():
        number = 1
        writeNumber(number)
        time.sleep(1)
        
#@webiopi.macro
def left():
        number = 2
        writeNumber(number)
        time.sleep(1)
        
#@webiopi.macro
def right():
        number = 3
        writeNumber(number)
        time.sleep(1)
        
#@webiopi.macro
def backward():
        number = 4
        writeNumber(number)
        time.sleep(1)

#@webiopi.macro
def servo_centre():
        number = 5
        writeNumber(number)
        time.sleep(1)

#@webiopi.macro
def servo_left():
        number = 6
        writeNumber(number)
        time.sleep(1)

#@webiopi.macro
def servo_right():
        number = 7
        writeNumber(number)
        time.sleep(1)        
        
#@webiopi.macro
def led_on():
	number = 8
	writeNumber(number)
	time.sleep(1)
	
#@webiopi.macro
def led_off():
	number = 9
	writeNumber(number)
	time.sleep(1)
	
# Start the webiopi server
server = webiopi.Server(port=8000, login="Hammerstein", password="Hammerstein")

# Register the macros
server.addMacro(stop)
server.addMacro(forward)
server.addMacro(left)
server.addMacro(right)
server.addMacro(backward)
server.addMacro(stop)
server.addMacro(servo_centre)
server.addMacro(servo_left)
server.addMacro(servo_right)
server.addMacro(led_on)
server.addMacro(led_off)

# Run default loop

webiopi.runLoop()

# Cleanly stop the server
server.stop()
Here is the html:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" /> 
<title>Hammerstein_Mobile_Control_Panel</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">

   	function stop() {
   	webiopi().callMacro("stop");
   	}
   
   	function forward() {
       webiopi().callMacro("forward");
    }

   	function left() {
       webiopi().callMacro("left");
    }

   	function right() {
       webiopi().callMacro("right");
    }

   	function backward() {
       webiopi().callMacro("backward");
    }

	function servo_centre() {
		webiopi().callMacro("servo_centre");
	}	
   	
   	function servo_left() {
       webiopi().callMacro("servo_left");
    }

	function servo_right() {
		webiopi().callMacro("servo_right");
	}
		
   function LED_On() {
       webiopi().callMacro("led_on");
    }
   
   function LED_Off() {
       webiopi().callMacro("led_off");
    }	

</script>


<style type="text/css">

.myButton {
   -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
   -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
   box-shadow:inset 0px 1px 0px 0px #ffffff;
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ffffff), color-stop(1, #f6f6f6));
   background:-moz-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-webkit-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-o-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:-ms-linear-gradient(top, #ffffff 5%, #f6f6f6 100%);
   background:linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
   background-color:#ffffff;
   -moz-border-radius:6px;
   -webkit-border-radius:6px;
   border-radius:6px;
   border:1px solid #dcdcdc;
   display:inline-block;
   cursor:pointer;
   color:#666666;
   font-family:Arial;
   font-size:15px;
   font-weight:bold;
   padding:6px 24px;
   text-decoration:none;
   text-shadow:0px 1px 0px #ffffff;
        width: 130px;
        height:30px;
        margin:1px;
}
.myButton:hover {
   background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f6f6f6), color-stop(1, #ffffff));
   background:-moz-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-webkit-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-o-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:-ms-linear-gradient(top, #f6f6f6 5%, #ffffff 100%);
   background:linear-gradient(to bottom, #f6f6f6 5%, #ffffff 100%);
   background-color:#f6f6f6;
        padding:6px 24px;
}
.myButton:active {
   color:#ff0000;
        position:relative;
   top:1px;
        padding:6px 24px;
}

</style>

</head>
<body>
<center><h3>Hammerstein Control Panel</h3></center><br>


<center>
<table>
<tr><td colspan=3 align="center"><button class="myButton" onmousedown="forward()" onmouseup="stop()">Forward</button></td></tr>
<tr><td><button class="myButton" type="button" onmousedown="left()" onmouseup="stop()">Left</button></td>
<td><button class="myButton" type="button" onclick="stop()">Stop</button></td>
<td><button class="myButton" type="button" onmousedown="right()" onmouseup="stop()">Right</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="backward()" onmouseup="stop()">Backward</button></td></tr>
<tr><td colspan=3 align="center"><button class="myButton" type="button" onmousedown="LED_On()" onmouseup="LED_Off()">LED_On</button></td></tr>
</table>
</center>

<center><h3>Sensor Control</h3></center><br>
<center>
<table>
<tr><td><button class="myButton" type="button" onclick="servo_left()">Scan Left</button></td>
<td><button class="myButton" type="button" onclick="servo_centre()">Centre</button></td>
<td><button class="myButton" type="button" onclick="servo_right()">Scan Right</button></td></tr>
</table>
</center>

</body>
</html>
Here is the Arduino Sketch:

Code: Select all

// Arduino Pin A5 to RPi SDA
// Arduino Pin A6 to RPi SCL
// Inspiration from Ocra Laing's Blog http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c

#include <Wire.h>
#include <Servo.h>

#define SLAVE_ADDRESS 0x04
int number = 0;
int state = 0;

// Setup Ultrasonic Sensor Pins
#define trigPin 12
#define echoPin 13

// Defines for reading distances 
#define microsecondsToCentimeters(microseconds) (unsigned long)microseconds / 29.1 / 2.0
#define MinActionDistance 40 // Set maximum allowaable distance to obstacle

// Setup motor controller pins for L298N
// Right Motor
int enA = 11;
int in1 = 8;
int in2 = 7;

//Left Motor
int enB = 4;
int in3 = 6;
int in4 = 5;

// Setup LED test pin
int Led = 10;

// Setup the servo
Servo myservo;

byte sweep_pos = 0;
byte pos_index = 90;
unsigned long left_dist, right_dist;

//Set unsigned integer variables to be used
unsigned int duration;
unsigned int distance;
unsigned int FrontDistance;
unsigned int LeftDistance;
unsigned int RightDistance;


void setup() {
  
  Serial.begin(9600); // Start serial for output
  Wire.begin(SLAVE_ADDRESS); // Initialise i2c as slave
 
  //Define callbacks for i2c communication
  Wire.onReceive(receiveData);
  Wire.onRequest(sendData);
  
  //Setup the servo
  myservo.attach(2); //Attaches the servo to pin 2 of the Nano
  myservo.write(90); //Set the servo to face front
  
  //Below set all the pin modes as OUTPUT as they will all be outputting data
  //Set modes for distance sensor pins 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  //Set modes for motor controller pins
  pinMode(enA, OUTPUT);   
  pinMode(enB, OUTPUT);   
  pinMode(in1, OUTPUT);   
  pinMode(in2, OUTPUT);   
  pinMode(in3, OUTPUT);   
  pinMode(in4, OUTPUT);

  //Set mode for Led test pin
  pinMode(Led, OUTPUT);

  // Declare ready
  Serial.println("Hammerstein Ready!");
}

void loop() {
  delay(100);
  unsigned long dist_fwd;
  //Rotate the sensor to check for obstacles
  //scan(); //Call the scan function
  ping();
  
}

// Callback for received data
void receiveData(int byteCount) {
  
  while(Wire.available()) {
    number = Wire.read();
    Serial.println("data received: ");
    Serial.println(number);
    
    if (number == 0) {
      Stop();
    } 
    if (number == 1) {
      Forward();
    }
    if (number == 2) {
      Left();
    }
    if (number == 3) {
      Right();
    }
    if (number == 4) {
      Backward();
    }
    if (number == 5) {
      Servo_Centre();
    }
    if (number == 6) {
      Servo_Left();
    }
    if (number == 7) {
      Servo_Right();
    }
    if (number == 8) {
      led_on();
    }
    
   if (number == 9) {
    led_off();
   }
  }
}

// Callback for sending data
void sendData() {
  Wire.write(number);
}

void scan() //This function tells the robot to scan for obstacles  
{
  if (sweep_pos <=0) {
    pos_index = 20;
  }
  else if (sweep_pos >=180) {
    pos_index = -20;
  }
  Serial.print ("pos_index = ");
  Serial.println(pos_index);
  sweep_pos += pos_index;
  Serial.print("sweep_pos = ");
  Serial.println(sweep_pos);
  myservo.write (sweep_pos);
}

void Servo_Centre()
{
  Serial.println("");
  Serial.println("Scanning Forward");
  if (sweep_pos != 90) { 
  myservo.write(90);
  sweep_pos = 90;
  }
}

void Servo_Right()
{
  Serial.println("");
  Serial.println("Scanning Right");
  if (sweep_pos != 20) {
    myservo.write(20);
    sweep_pos = 20;
  }
}

void Servo_Left()
{
  Serial.println("");
  Serial.println("Scanning Left");
  if (sweep_pos != 160) {
    myservo.write(160);
    sweep_pos = 160;
  }
}

void led_on()
{
  Serial.println("");
  Serial.println("Led On");
  digitalWrite(Led, HIGH); 
}

void led_off()
{
  Serial.println("");
  Serial.println("Led Off");
  digitalWrite(Led, LOW);
}

//Read the HC-SR04 sensor
unsigned long ping()
{
  //Trigger the sensor to send out a ping
  digitalWrite (trigPin, LOW);
  delayMicroseconds (5); 
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  //Measure how long the ping took to return and convert to centimeters
  return (microsecondsToCentimeters (pulseIn (echoPin, HIGH)));
}

void Forward()                                    //This function tells the robot to go forward 
{
  Serial.println("");
  Serial.println("Moving forward");
  // turn on left motor   
  digitalWrite(in1, HIGH);   
  digitalWrite(in2, LOW);   
  // set speed out of possible range 0~255
  analogWrite(enA, 245);   
  // turn on right motor   
  digitalWrite(in3, LOW);   
  digitalWrite(in4, HIGH);   
  // set speed out of possible range 0~255   
  analogWrite(enB, 130);   
  //delay(100);
}

void Backward()                                  //This function tells the robot to move backward
{
  Serial.println("");
  Serial.println("Moving backward");
  // turn on left motor   
  digitalWrite(in1, LOW);   
  digitalWrite(in2, HIGH);   
  // set speed out of possible range 0~255
  analogWrite(enA, 245);   
  // turn on right motor   
  digitalWrite(in3, HIGH);   
  digitalWrite(in4, LOW);   
  // set speed out of possible range 0~255   
  analogWrite(enB, 130);   
  //delay(100);
}

void Left()                                      //This function tells the robot to turn left
{
  Serial.println("");
  Serial.println("Moving left");
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
// set speed out of possible range 0~255
  analogWrite(enA, 245); 
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
// set speed out of possible range 0~255   
  analogWrite(enB, 130);   
  //delay(100);  
}

void Right()                                    //This function tells the robot to turn right
{
  Serial.println("");
  Serial.println("Moving right");
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
// set speed out of possible range 0~255
  analogWrite(enA, 245); 
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enB, 130);
  //delay(100);
}

void Stop()                                     //This function tells the robot to stop moving
{
  Serial.println("");
  Serial.println("Stopping");
// now turn off motors   
  digitalWrite(in1, LOW);   
  digitalWrite(in2, LOW);
  analogWrite(enA, 0);  
  digitalWrite(in3, LOW);   
  digitalWrite(in4, LOW);
  analogWrite(enB, 0);
}
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

Rovracing
Posts: 1
Joined: Wed Aug 05, 2015 11:37 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Wed Aug 05, 2015 11:45 pm

cool project - I'll PM you with some questions.
-p

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 572
Joined: Sat Nov 02, 2013 2:06 pm

Re: Which Software Route - RPi / Arduino Web Controlled Robo

Thu Aug 06, 2015 6:30 pm

Rovracing wrote:cool project - I'll PM you with some questions.
-p
No worries, happy to pass on anything I can to help, I am hoping to get the Robot put back together for our Pi Jam on Saturday, I'll post up some Pics.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

Return to “Automation, sensing and robotics”