Model Boat Mayhem

Please login or register.

Login with username, password and session length.
Pages: [1]   Go Down

Author Topic: Seabex One rebuild and taking it to the next level  (Read 12264 times)

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Seabex One rebuild and taking it to the next level
« on: April 01, 2012, 05:56:31 PM »

Hello fellow builders,
Allow me to introduce myself. I'm Danny, 38 years old and I live in the Netherlands near the city of Rotterdam. So please don't rant about small typos, English is not my native language. I've been building modelboats for some time now, preferably with a lot of functions. But there is a problem. The new 2.4 gHz transmitters can't work with the encoders/decoders of the days when 40/35/27 mHz ruled. That's why I went looking for different methodes of sending codes to the boats. About 2 years ago a good friend of mine asked me: Why don't you put a computer in it? A computer? Way to big. But I was wrong. I came in contact with a little piece of equipment called Arduino. And that was the beginning of a lot of experiments with some good and some bad results.

Last year I had a encoder/decoder system that worked with the transmitter by using 2 digital potmeters (10K) to devide the channels. I sends 16x16 commands/codes over 2 channels of the transmitter. Seems a lot, and it worked OK, but I wanted more and I wanted it more universal.

The system now is a standalone version that can work next to the transmitter or, like I will be doing, instead of a transmitter. I have two Arduino's talking wirelessly to each other (so feedback about the batterystate, course, motortemp. And more is possible). I have a max distance of about 1,5km/1mile. My setup will be a tabletPC with touchscreen as transmitter (interface instead of the Futaba F14 brick) talking over a USB or bluetooth to a small ArduinoNano which is coupled to a nRF24L01-transmitter/receiver unit (legal 2,4gHz). In the boat there will be another Arduino with the same transmitter/receiver unit. In the boat there will be a few other bits and pieces been build for better and more reliable functioning of the boat.

It all sounds like Science Fiction and dreams of someone who doesn't know a thing about modelboats. Sorry to say then that it already works in a small Kormoran boat which I use for testing and development of the parts and the programming.

Photo of the boat:






First of the boat itself:
I have this boat for some time now and hasn't seen much water. Most functions worked, but I got fed up with the expensive encoder/decoders. First thing on the list will be the access to the boat. I don't like the small openings in the deck and the envelop under the superstructure.

Photo inside:


Under the decks I made a led-strip so I can work on the inside of the boat without sitting in my own light and fiddling in a half dark space.

The decks will also be re-made. They will be more rigid and will get real wood instead of the stickers.





The protocol for sending data is simple and effective. I devided the touchscreen in sections. Most of the time you won't be using the deckcrane together with navigation and so on. Every 10ms a command is send. A complete data-set from a section tkaes about 40ms. The servocommands are called with a underscore letters (a to z) and a number (0-255) for position. The on/off kind of functions are kapital letters (A to Z) and a code. The code is a digital calculation which creates a unique number for 8 digital input. It's a simple matter of adding and substracting numbers.
You start with 0, Command 1 adds 1, command 2 adds 2, command 3 adds 4, command 4 adds 8, command 5 adds 16, command 6 adds 32, command 7 adds 64 and finally command 8 adds 128. So if I want to switch command 5 and 7, the code will be 16+64 = 80 and so on. When the command reaches the boat, the letter is first read and the program will start the above system in revered order. Is the command higher or the same as 128, no? Next. Is is higher or the the same as 64? yes, execute command and substract 64, and so on.

This is the "Transmitter" ArduinoNano with the nRF. I now have it in a small box with it's own battery and a bluetooth module.


All the servo's get their own powersupply. From the arduino there will be only one (signal) wire goning to the servo. The +/- wires will come from a 7805-ic. Here's is a small illustration how it works. Sorry for the dutch words in it, I already started a topic about this boat on a dutch forum. “accuzijde” means battery-side, “ontvangerzijde” means receiverside, which can be the receiver in a standard setup or a servo. Most of the PCB's will be created in a free program called Fritzing. And from there they will be printed and etched. By the way, the split powersupply will also work no standard radio gear and will result in less noise and better/faster/stronger respons on the servo's.



In this topic I try to explain how some of the electronics work and sometimes there will be a few pieces of programming code so people can experiment themselfs with the arduino's.

Untill next time,

Danny
Logged

Norseman

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,484
  • Location: Huyton, Liverpool
Re: Seabex One rebuild and taking it to the next level
« Reply #1 on: April 01, 2012, 06:08:50 PM »

Hi Danny

Welcome to Mayhem and it's members all over the world

I'm sure lots of people will be interested in your Seabex controls. I'll tag along and hope to learn something new.

Regards Dave
Logged

dave301bounty

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 665
  • Location: Wavertree
Re: Seabex One rebuild and taking it to the next level
« Reply #2 on: April 01, 2012, 07:07:28 PM »

Hey  that is very clever stuff neat looking model too ,well done .
Logged

Capt Podge

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,426
  • Location: Blyth, Northumberland
Re: Seabex One rebuild and taking it to the next level
« Reply #3 on: April 01, 2012, 07:17:34 PM »

WOW ! :o :o :o :o

....and I'm still trying to master the soldering iron :((

Watching with interest anyway :-))

Regards,

Ray.
Logged
Pop top campervan needed

oldiron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,323
  • Location: Lindsay, Ontario, Canada
Re: Seabex One rebuild and taking it to the next level
« Reply #4 on: April 01, 2012, 08:45:06 PM »

I'm going to follow your Seabex work with interest. i have one myself I built from the kit. As you have said, the kit access holes are very small. I built mine, from the outset, with large openings and I haven't been sorry. in the spirit of offering suggestions, here are pictures of mine pulled apart.

John











Logged

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #5 on: April 01, 2012, 09:04:36 PM »

Thanks John,
Belief it or not, but your Seabex sparked the idea for my Seabex to rebuild the rear and front deck. I was first planning to just make a hatch for the battery. Now I have, just like you, the full front part open, a battery hatch, rear end opens and the side pieces next to the Moonpool are open. Every part is a watertide section with, in time, each it's own wateralarm. Have you changed anything to the schottel-units?

Danny
Logged

oldiron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,323
  • Location: Lindsay, Ontario, Canada
Re: Seabex One rebuild and taking it to the next level
« Reply #6 on: April 02, 2012, 03:46:36 AM »

Thanks John,
Belief it or not, but your Seabex sparked the idea for my Seabex to rebuild the rear and front deck. I was first planning to just make a hatch for the battery. Now I have, just like you, the full front part open, a battery hatch, rear end opens and the side pieces next to the Moonpool are open. Every part is a watertide section with, in time, each it's own wateralarm. Have you changed anything to the schottel-units?

Danny

  I've kept the shottel units stock. They seem to work fine. Some have said they have problems steering with them. I haven't noticed any such problems. Do keep your speed down though, or you'll get a good wave coming out of the moon pool onto the rear deck.
 If you're computer operating yours you should be able to run all the Shottel units individually as on the prototype.

John
Logged

Tug-Kenny

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 7,671
  • Location: Newport. S Wales
Re: Seabex One rebuild and taking it to the next level
« Reply #7 on: April 02, 2012, 11:31:41 AM »


I will also be following this with interest. There is always a demand for more channels and this looks to be a way of doing it.   :-))

A slight side track.  Who makes the SeabexOne kit please ?


cheers

ken
Logged
Despite the high cost of living   .......... It remains popular

Andy_k

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 73
  • Location: Pembrokeshire
Re: Seabex One rebuild and taking it to the next level
« Reply #8 on: April 02, 2012, 11:34:30 PM »

Fantastic I will be watching this with great interest as I have one to build up in the coming weeks so looking forward to soaking up all the information  :-))
keep up the good work
Andy :}
Logged
Right which one will I do next?;)

Andy_k

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 73
  • Location: Pembrokeshire
Re: Seabex One rebuild and taking it to the next level
« Reply #9 on: April 02, 2012, 11:37:10 PM »

Quote
A slight side track.  Who makes the SeabexOne kit please ?


cheers

ken



Ken the kit was manufactured by Graupner but out of production
Andy
Logged
Right which one will I do next?;)

Tug-Kenny

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 7,671
  • Location: Newport. S Wales
Re: Seabex One rebuild and taking it to the next level
« Reply #10 on: April 03, 2012, 09:44:04 AM »



Thanks Andy.   :-))


ken

Logged
Despite the high cost of living   .......... It remains popular

tugboyben

  • Kirkleesmodelboatclub
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 695
  • WARRIOR TUG BOAT
  • Location: LIVERSEDGE
Logged

Tug-Kenny

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 7,671
  • Location: Newport. S Wales
Re: Seabex One rebuild and taking it to the next level
« Reply #12 on: April 07, 2012, 12:17:26 PM »


COR     :-))

Long way to collect in Lancashire though.


ken
Logged
Despite the high cost of living   .......... It remains popular

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #13 on: May 11, 2012, 11:36:30 AM »

Hi guys,
I'm still here and still working on the Seabex. I've been busy (in my very little sparetime) trying to organize my electronics. On the picture you see a ArduinoMega2540 as a central control unit, Arduino Nano as a communication unit and a Nano with a LCD for debugging. The rest are a few servo's, trimpots, stepperdrivers for the schottel unit, esc's and some more stuff that's planned but still in research fase. The protocol is being tested and still going well. Still no lack in the system and the main problem I found is the sun that keeps me from seeing the display of the tabletPC. As you can see, the servo's each have their own powersupply by means of a 7805 IC.
These functions are for navigation, positioning and tilt compensation (a standard Seabex can tilt a lot when using a crane or with a little breeze).

Keep you posted.

Best regards,

Danny

Links to higher resolution: http://i478.photobucket.com/albums/rr149/DDvDijk/SeabexOne/Arduino2540_CC_HI.jpg

Logged

Norseman

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,484
  • Location: Huyton, Liverpool
Re: Seabex One rebuild and taking it to the next level
« Reply #14 on: May 11, 2012, 02:06:25 PM »

Hi Danny

I am sure your electronics are going to be well beyond me but I will watch with interest.
I'm quite intrigued at what you will achieve......
 {-) think of the Rabbit caught in the headlights - yep that's me with electronics {-)

Dave
Logged

boatmadman

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 2,719
  • Location: South Cumbria
Re: Seabex One rebuild and taking it to the next level
« Reply #15 on: May 11, 2012, 02:17:25 PM »

Nice work. Tell us more about the positioning aspect of the installation, please.

Ian
Logged
if at first you dont succeed.....have a beer.....

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #16 on: May 11, 2012, 04:21:27 PM »

Positioning can be split into two parts. Electric and the ship itself.

First electric. As many of you know, there is something called DPS. That stands for Dynamic Position System. My rc version will consist of a metal ring with two Neodyme (rare earth) magnets. Through the ring I can lower a small weight on a thin wire that sits on the bottom of the lake (in my case about 2 metre/6 foot max.). When the ship moves sideways the ring with the wire will also move, even if the weight is not on the bottom it will work. Now I can meassure the distance of the magnets movement with some HAL-sensors and calculate the force working against the ship. I can meassure change from less then a 10th of a millimetre. Second part is the ship itself. In position mode (I have Position and navigation mode) the schottel units will all be at a 45 degree angle and all of them are pushing at 1/4 speed. The calculated force will be mixed in with the speed and the various schottels will go slower or faster then the others. That way the ship can move side ways, forwards reverse and turn according what is needed. The rotation of the ship is meassured with a HH-gyro of my helicopters in combination with a small digital compass unit (www.sparkfun.com) which works on the i2c on the Arduino. All parts and sensors are functioning and separate from the ship it also functions very nice. Only time will tell if it will give me what I want. To help the system a bit, there will also be a small side thruster be build in the bow.

Apart from this, there is also a gyro system that meassures the tilt of the boat and shifts the batteries side ways to keep the ship steady. I'm still testing if it will be done with a gyro or just a stick with a weight hooked up to a potmeter to meassure the tilt.

I hope this clearifice it a bit.

Danny
Logged

YJRR2

  • Shipmate
  • *
  • Offline Offline
  • Posts: 6
Re: Seabex One rebuild and taking it to the next level
« Reply #17 on: May 13, 2012, 07:30:32 PM »

Danny,

I'm really interested in your Arduino set-up but the picture you posted - even the hi-res link - is difficult to make out any detail; not sure if this is the same for everyone!?

If possible, could you post a clearer diagram?

I'm just dabbling with electronics at the moment but the Arduino boards look like they have a lot of potential as a control system.
It looks like all servo's/ESC's will need their own power supply though as the boards can't carry much current. I will continue to watch your progress with much interest.

 :-))
Logged

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #18 on: May 16, 2012, 11:48:21 AM »

tried to get a bigger/better quality picture on the photobucket, but it seems they resize it. For anyony interested I can send a (large) jpg with all the parts so far.

Danny
Logged

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #19 on: May 22, 2012, 11:06:44 AM »

Hi guys,
First up is the Debug-unit. There is also a slight change in the setup. The receiver nano is no longer needed. This way, people can make a "lite" version of the system with just 2 mega's and 2 nRF24L01 units. The debugger isn't necessary but a nice feature. The unit will also carry a i2c port for max. 14 PCF8574 port expanders with each 8 digital functions (yes, that 112 functions, not that I need it, but it is possible). The lite version can control 13 pwm and about 45 digital functions.

De debug unit also has 2 on-off-on switches and 2 push buttons. They will control the menu's (up/down/left/right/enter/home). That way I can scroll through feedback functions, transmitted functions, and control function without the use of a transmitter/controller. The 2 pots on the right are for controlling contrast and backlight. On the left side of the box there is also an external resetbutton for the Nano inside. Next to the reset button thee is a DIN-plug for programming. The unit can be powered on the right side, and there is a external RX/TX/GND port for communication with the central controller.

Best regards,

Danny

PS: yes, it still needs paint.



Logged

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #20 on: May 22, 2012, 11:54:30 AM »

Just a little testing code for the debugger:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define expander B0111001  // Address with three address pins grounded.
            // Note that the R/W bit is not part of this address.
                           // B0111000 = ap
                           // B0100000 = p


int pinwaarde;
int pinnummer;

uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = {   0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
 
LiquidCrystal_I2C lcd(0x38,16,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();
 
  lcd.createChar(0, bell);
  lcd.createChar(1, note);
  lcd.createChar(2, clock);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();
 
  lcd.print("Hello world...");
  lcd.setCursor(0, 1);
  lcd.print("   i ");
  lcd.print(3, BYTE);
  lcd.print(" arduinos!");
  expanderWrite(B00000000);
//  displayKeyCodes();
 
}

void loop() {
  pinwaarde = (expanderRead());
  lcd.setCursor(16, 1);
////////////////////////////////// NONE ///////////////////////////////
   if (pinwaarde <= 0) {
    pinnummer = 0;
        lcd.print("Button: NONE         ");
    } 
////////////////////////////////// PIN 8 ///////////////////////////////
   if (pinwaarde >= 128) {
    pinnummer = 8;
    pinwaarde = (pinwaarde - 128); }
  //  else{ pinnummer = 80; }
////////////////////////////////// PIN 7 ///////////////////////////////
   if (pinwaarde >= 64) {
    pinnummer = 7;
    pinwaarde = (pinwaarde - 64); } 
////////////////////////////////// PIN 6 ///////////////////////////////
   if (pinwaarde >= 32) {
    pinnummer = 6;
      lcd.print("Button: HOME");
    pinwaarde = (pinwaarde - 32); }   
////////////////////////////////// PIN 5 ///////////////////////////////
   if (pinwaarde >= 16) {
    pinnummer = 5;
      lcd.print("Button: ENTER");
    pinwaarde = (pinwaarde - 16); }   
////////////////////////////////// PIN 4 ///////////////////////////////
   if (pinwaarde >= 8) {
    pinnummer = 4;
      lcd.print("Button: LEFT");
    pinwaarde = (pinwaarde - 8); }   
////////////////////////////////// PIN 3 ///////////////////////////////
   if (pinwaarde >= 4) {
    pinnummer = 3;
      lcd.print("Button: RIGHT");
    pinwaarde = (pinwaarde - 4); } 
////////////////////////////////// PIN 2 ///////////////////////////////
   if (pinwaarde >= 2) {
    pinnummer = 2;
      lcd.print("Button: DOWN");
    pinwaarde = (pinwaarde - 2); }   
////////////////////////////////// PIN 1 ///////////////////////////////
   if (pinwaarde >= 1) {
    pinnummer = 1;
      lcd.print("Button: UP  ");
    pinwaarde = (pinwaarde - 1); }   
////////////////////////////////// DEBUG ///////////////////////////////

  delay(100);
}


void expanderWrite(byte _data ) {
  Wire.beginTransmission(expander);
  Wire.send(_data);
  Wire.endTransmission();
}

byte expanderRead() {
  byte _data;
  Wire.requestFrom(expander, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}
Logged

F4TCT

  • I am not completely useless.......I can always serve as a BAD example
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 535
  • Location: Whitby, North Yorkshire, UK
    • My Boat Builds
Re: Seabex One rebuild and taking it to the next level
« Reply #21 on: May 22, 2012, 01:29:30 PM »

ooooooooooooooooooooooooooooooooooooooooooookay....

I wish i understood programming, however i think many of us dream to have to ability to make a proper gadget filled model with loads of features..

Looking forward to the rest of the build.

Dan
Logged

flashtwo

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 521
  • Location: Sevenoaks, Kent, England
Re: Seabex One rebuild and taking it to the next level
« Reply #22 on: May 22, 2012, 06:04:57 PM »

Hi Danny,

Its very interesting that you have chosen the Arduino. On this website the "Raspberry PI" computer board was discussed as a possible computer to use in model boats, but I suggested that the Arduino was more appropriate because it had motor and ESC interfaces already developed.

I have been using PIC controllers on my steam boat (see "Flash steam plant control" thread  - http://www.modelboatmayhem.co.uk/forum/index.php?topic=15817.90 )

You are very wise to power the servos separately from the Arduino circuits - I had trouble with electrical interference from the servos when they were powered from the same voltage regulator as the electronics.

Are you programming the Arduino in "C" or is it a language to do with "Fritzing"? I found it very useful to annotate the software with lots and lots of comments, since I could easily forget why I had written the software as it was. During developement of my software I had to keep a good record of the different versions (V1, V2 etc) so that I could revert back to a version that worked!

I have been writing my software in assembler which is hard work - it is so much better if you can use software that has already been written and tested.

Using a computer control system is good, since ideas can be tried out without lots of re-soldering of the electronics.

Could you send me a personal message with a better diagram?

Good luck

Ian
Logged

SeabexOne

  • Shipmate
  • *
  • Offline Offline
  • Posts: 8
Re: Seabex One rebuild and taking it to the next level
« Reply #23 on: May 23, 2012, 06:29:27 PM »

Hi guys,
Since I also want to use a lot of steppermotors for this boat, I had to create a little code. This code makes the startup position 0 and input in the serial monitor is the letter A (for motorA) and any value between -180 and 180. The letter S and any number between 0-2000 (max for my motors) for the speed and P and any number between 0-1000 for steppower. Type the letter R followed by an enter to reset the system (soft reset) and make current position 0.

There is also a possiblitiy to add a switch to enter calibration mode (led 13 lights up). With a potentiometer, it is possible to slowly move te stepper to the desired position. After switching off the calibration mode, the arduino will softreset and make the position zero.

Hope it is clear what's going on in the code. I tried to comment it to make it more readable. All configurable items are in the config part for easy adaption for your own purposes. I do all programming in the GUI from Arduino, it is C++ based with a lot of extra libraries to make things easier.

Best regards,

Danny

Code: [Select]
// Based upon the stepper library from StepperLab3
// Code adaption by Danny van Dijk, Hoogvliet, The Netherlands
// Please feel free to use the ideas, make them bettter and share.
// Analog input on A0 for calibration. Switch (with pull down) to pin 8
// commands in SerialMonitor: Axxx (xxx = -180 to 180) for heading steppermotorA
//                            Sxxxx = setspeed 0-2000 / default 1000 (can be set in config) 
//                            Pxxxx = setpower 0-1000 / default 900 (can be set in config)
//                            R = reset arduino (short reset -> fast boot)
// Switch to calibration for setting new 0 point with the pot.
// Serialmonitor is set to 115200 BAUD.
// Tested with 28BYJ-48 Steppermotors and ULN2003 / Controller ArduinoUno-328


// import stepper library
#include <StepperLab3.h>

// create instance for stepper
StepperLab3 myStepper;

///////////////////////// CONFIG PART /////////////////////////

char buffer[5];          // how much can we input in the serial monitor
int reset = 0;           // calibration mode off
int heading;             // temporary heading
int motorsteps=1019;     // how many steps for a half turn / 180 degrees left and right
int steppower=900;       // Steppower
int stepspeed=1000;      // speed = 1000* 100ms = 100 steps/second
int offset=0;            // temporary offset
int sensorPin = A0;      // select the input pin for the potentiometer
int sensorValue = 0;     // temporary sensor value
int sensorMin = 0;       // minimum sensor value from pot
int sensorMax = 1023;    // maximum sensor value from pot
int stepAvalue=0;        // temporary Step Value
int motor1_1= 2;
int motor1_2= 4;
int motor2_1= 3;
int motor2_2= 5;
int buttonPin = 8;       // the number of the pushbutton pin
int ledPin =  13;        // LED indicator for calibration mode
int buttonState = 0;     // variable for reading the pushbutton status

////////////////////// END OF CONFIG PART //////////////////////

void setup(){
  Serial.begin(115200);
  Serial.println(" Serialstepper has been reset");
 
// initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);     
 
// initialize the pushbutton pin as an input:
   pinMode(buttonPin, INPUT);
   myStepper.attach(motor1_1,motor1_2,motor2_1,motor2_2);
   myStepper.setPower(steppower);
   myStepper.setSpeed(stepspeed);
   myStepper.setFullStep();

}

void loop(void)
{
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH);
    // read the potentiometer
    sensorValue = analogRead(sensorPin);
    //calculate degrees te steps 
    sensorValue = map(sensorValue,sensorMin,sensorMax,-motorsteps,motorsteps);
    myStepper.setPower(steppower);   
    myStepper.setSpeed(stepspeed);   // speed = 1000* 100ms = 100 steps/second
    myStepper.absoluteSteps(sensorValue); 
    reset = 1; // set resetvalue so when calibration is over, the arduino softresets
  }
  if (buttonState == LOW && reset == 1) {     
    digitalWrite(ledPin, LOW);
  void(* resetFunc) (void) = 0; //declare reset function @ address 0
    resetFunc();  //call reset
  }
 
 
  if (Serial.available() > 0) {
    int index=0;
    delay(10); // let the buffer fill up
    int numChar = Serial.available();
    if (numChar>5) {
      numChar=5;
    }
    while (numChar--) {
      buffer[index++] = Serial.read();
    }
    splitString(buffer);
  }
}
void splitString(char* data) {
//  Serial.print("Data entered: ");
//  Serial.println(data);
  char* parameter;
  parameter = strtok (data, " ,");
  while (parameter != NULL) {
    setLED(parameter);
    parameter = strtok (NULL, " ,");
  }
  // Clear the text and serial buffers
  for (int x=0; x<5; x++) {
    buffer[x]='\0';
  }
  Serial.flush();
}


void setLED(char* data) {

//stepper A
  if ((data[0] == 'a') || (data[0] == 'A')) { // turn to heading
    int stepAvalue = strtol(data+1, NULL, 10);
    int heading = stepAvalue;   
    if (offset>=0){
      stepAvalue = stepAvalue+offset;
    }
    if (offset<0){
      offset=offset*-1;
      stepAvalue = stepAvalue-offset;
      offset=offset*-1;
    }   
    stepAvalue = map(stepAvalue,-180,180,-motorsteps,motorsteps); //calculate degrees te steps
    myStepper.setPower(steppower);
    myStepper.setSpeed(stepspeed);
    myStepper.absoluteSteps(stepAvalue);
    Serial.print("Steppower: ");
    Serial.print(steppower);
    Serial.print("    Stepspeed: ");
    Serial.print(stepspeed);
    Serial.print("    position: ");
    Serial.print(heading);   
    Serial.print("    step: ");
    Serial.println(stepAvalue);   
    }
  if ((data[0] == 'r') || (data[0] == 'R')) {
    offset = strtol(data+1, NULL, 10);
      void(* resetFunc) (void) = 0; //declare reset function @ address 0
      resetFunc();  //call reset
    }
      if ((data[0] == 's') || (data[0] == 'S')) {
    stepspeed = strtol(data+1, NULL, 10);
    }
      if ((data[0] == 'p') || (data[0] == 'P')) {
    steppower = strtol(data+1, NULL, 10);
    }
}
Logged

Norseman

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,484
  • Location: Huyton, Liverpool
Re: Seabex One rebuild and taking it to the next level
« Reply #24 on: June 11, 2012, 09:03:28 PM »

Hi guys
AlisterT posted this link up in the raspberrypi thread but I thought it may interest those reading this thread too
http://www.pololu.com/catalog/category/12
It's not clockwork so I won't need it {-)

Dave
Logged
Pages: [1]   Go Up