Page 1 of 1

Connecting Pi robot to router

PostPosted: Wed Mar 18, 2015 11:42 am
by Lt904
Hello,

I was wondering whether it is possible to connect the Pi robot to a router's wifi network and then control it from any device connected to the same network, as opposed to the Pi robot creating its own network.

Also, how easy would it be to add a button to the Pi robot's html control page that can be used to control pins on the Pi or Dagu mini driver? I'm reasonably confident with html, python and arduino scripting, but have never attempted to mesh them all together myself before. The reason for this is, I've mounted a little LED array on the Pi bot's pan/tilt head that acts as a headlight of sorts, however as it's powered by pins on the bot's control boards it is always on by default, it would be nice (although not essential) to be able to switch it on and off at the touch of a button that shifts IO pins from high to low.

Thanks!

Re: Connecting Pi robot to router

PostPosted: Thu Mar 19, 2015 4:25 pm
by Alan
Hi there,

Connecting the robot to a router is fairly straightforward, although it does involve editing text files I'm afraid. Essentially you need to edit the network configuration in the /etc/network/interfaces file. Adafruit have a good tutorial showing how to do this here.

With regards to adding a button to the web interface that controls pins on your Pi, you'll need to make changes to a couple of layers of the code. Firstly you need to add the button to the web interface, the button should send a text command, something like

Code: Select all
$( "#btnTurnOnLEDs" ).click( function() {
     if ( socket.readyState == SockJS.OPEN )
     {
         socket.send( "TurnOnLEDs" );
     }
}


Then you need to open up robot_web_server.py and edit the command handler that starts at line 83 (on_message). You need to add a clause to handle your command, something like

Code: Select all
elif lineData[ 0 ] == "TurnOnLEDs":
                   
    # Python code to turn on LEDs goes here


If you look at the other elif statements you should be able to get an idea of how we handle commands, and how you can pass arguments along with the commands.

Now, probably the easiest thing to do would be to control the Pi GPIO pins in Python to turn the LEDs on and off. It is possible to control the pins on the Mini Driver, but you'll need to write a fair bit more code in another 2 to 3 layers... :? All the layers are there to give people a nice experience when they're getting started, but there can be a fair bit to dig through if you want to make changes.

If you decide that you'd like to control the pins on the Mini Driver then I suggest reading through this forum post which gives a brief overview of what all the levels do, then I can give you some guidance for how to make the changes.

Hope that helps.

Regards

Alan

Re: Connecting Pi robot to router

PostPosted: Fri Apr 24, 2015 11:27 pm
by Lt904
Hi Alan,

Thanks for your reply, I have managed to get the button to turn the LEDs on and off no problem! Although I couldn't get the robot to connect to a router, I tried following the tutorial all the way through, but found that the bot connects to my router for about a minute and it gets an IP address, but I can't connect to it using the router assigned IP address. After a minute or so, the bot just disconnects from the router...

Any thoughts?

Thanks again,
Tom.

Re: Connecting Pi robot to router

PostPosted: Sat Apr 25, 2015 12:13 am
by Alan
Hi Tom,

Thinking about it, it's possible that some of the set up I put in place to support having the robot act as an access point could be interfering as you try to connect to the router.

Could you try following the instructions I give in the last post of this thread? Also, if you have a spare SD card with an installation of Raspbian, could you try connecting to the router with that just to make sure that your setup is correct?

Regards

Alan