Thursday, November 19, 2015

RASPBERRY WEB SERVER SENDING DATA OF GET TO ARDUINO NANO



Arduino based all devices are simply programmable and easily execuable.By using this we can create maximum number of devices even that its provide a very broad platform to create any device.
It is a small project, I did for a partner who is build a 1/48 scale RC model of a Fletcher class Destroyer.He asked if I could animate the 5 x MKIII 5"/38 gun turrets, complete with bearing and elevation, and also being able to individually control them, or control them in selectable groups, as per the real thing.
So after 3 days of researching, testing and fine tuning, I have 1- Raspberry Pi (B), running as a WAP + apache, php, python + CGI support 1- Arduino Nano, getting data from the Raspberry serial comms pins, 3- pan/tilt units that represent the 3 fwd turrets 1- web interface in that I can set the bearing and elevation of any chosen gun and a "go" button and using my encourage to control them.
Passing the gun number, bearing and elevation as GET request variables, using a python CGI script to get those variables and send them to the Arduino.
The video shows the servos moving at full speed, but I have since changed from the servo.h arduino library to the VarSpeedServo.h library and can set the speed to something a bit more sensible. It also makes the servos appear to move together rather than in sequence.
I also made up a proper circuit board to contain a 26 pin socket for the Raspberry ribbon cable, a basic voltage divider for a logic level converter, headers for plugging the nano into and header pins for the servo connections. It also appears to cleaned up a lot of the servo jitter I was getting.

[Edit] - Due to popular demand...(both of them)...I have now written a more complete instructable...so here we go



Step 1:You want to need these things
·         Raspberry Pi having 4 to 8Gb SD Card and micro USB cable.
·         USB WIFI dongle - Something like the Edimax EW-7811Un 150 Mbps Wireless 11n, but try and get one using the RealTek or Atheros chipsets. It's less likely you will have driver problems A number of servos - This project used 6- TowerPro 9g micro servos.
·         Arduino Nano
·         3-Pan/Tilt servo mount
·         1 x 3.3k and 1 x 1.6k 1/4 watt resistor - These are to make up the voltage divider for the logic level converter
If you want make up a proto board for the nano, Raspberry connector,header and servo headers, you also need:
·         26 pin (2 x 13) pin male header,
·         2 x 10 pin stackable female headers (for the nano to plug into),
·         Enough standard header pins for the number of servos. In my case, 3 rows of 6 pins arranged in an 18 pin block
·         26 pin double row (2 x 13) female/female ribbon cable,
·         A 2 terminal screw connector block.



Step2: RaspberryPi as a WAP and jQuery Simple Slider support

By using the telnet into Rosberry Pi via a cat5 cable and joind the Rasberry with my  lappi wifi.

You Update your raspberry by using these key wards:
·         "sudo apt-get upgrade"
·         Reboot, then log back in once it has booted
·         "sudo apt-get update",
Now we highlight all of the code in the file "gcs-php.txt", rightclick and copy.
In the Pi telnet terninal, open a new file called "gcs.php"...or whatever you want to call it
·         "sudo nano gcs.php"
By rightclick in the putty terminal window and the clipboard will immediately paste into the nano editor.
You also need the form handler cgi script to send the signals to the Nano..
Create a new directory in /usr/lib/ called "cgi-bin"
Open a new file called "gcs.py" (sudo nano /usr/lib/cgi-bin/gcs.py)
Copy and paste the code from gcs-py.txt into the nano editor, then save and close like we did above.
Make the file executable with "sudo chomd 777 /usr/lib/cgi-bin/gcs.py"
The one part that could trip you up here is the connection device. Do a "ls /dev/tty*" and see what is listed. Then connect your USB cable between the raspberry and the Nano, and all going well, you should see "ttyAMA0" (that's a zero..not an 'oh'). If it shows something different, then change the python code to reflect the proper device number.

Step3:set up time to pi as a wap

Here somr links are given below by which you can gain all the details about the Rosberry


By creating a program specially for java writing you set your time.
You can tweak the page code and customize the page and slider names/values to suit your needs.
At this stage, you can shut the Pi down and close any telnet/ssh/putty sessions you have open to it.

Step 4: Now for the Arduino bit..

Add the VarSpeedServo library to your Arduino IDE using the usual library import method.And you can find the library from given below link.
After creating a library you can control the speed of motor.In a Arduino control a motor through coding is very tuff task and also interesting.But timing should not mesh with the PWM timing. There are 3 parts to the servo method,speed and "wait for move to finish". Check out the sketch, and you'll see it is pretty straight forward. Copy and paste the sketch from the attached txt file, paste into a new sketch and upload to the Nano. I'm still learning this language, and it is probably a very bad, round about way of doing it, but it works, so don't be too harsh on me.

No comments:

Post a Comment