Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Displays / Re: SEEED 2.8 TFT V2 TouchScreen Button Toggle issue. on: April 30, 2014, 05:50:08 pm
UPDATE///
The button 3 issue is fixed, the problem was in the wiring. Now i just need to smooth out the buttons.

2  Using Arduino / Displays / SEEED 2.8 TFT V2 TouchScreen Button Toggle issue. on: April 25, 2014, 11:48:43 am
   This sketch works properly, as it does everything I expected, but I am unhappy with the performance. The buttons are too quick to respond. I think I need some kind of "debouncing" to make the buttons less responsive.
   Now for the unexpected part : Button 3 will change states on its on from time to time. I dont even have a guess about that one.
So, any help would be appreciated.

This Sketch is running on a MEGA 2560 with a seeedstudio 2.8 tft v2 display

Code:
/*


/*-----( Import needed libraries )-----*/
#include <stdint.h>
#include <TouchScreen.h>
#include <TFTv2.h>
#include <SPI.h>
#include <Wire.h> // specify use of Wire.h library.

/*-----( Declare objects )-----*/
/* create variable to store High  Level Sensor status */
boolean LED_1_State = LOW;//storage for the current state of the LED (off/on)
boolean LED_2_State = LOW;//storage for the current state of the LED (off/on)
boolean LED_3_State = LOW;//storage for the current state of the LED (off/on)
boolean LED_4_State = LOW;//storage for the current state of the LED (off/on)
boolean LED_5_State = LOW;//storage for the current state of the LED (off/on)
boolean LED_6_State = LOW;//storage for the current state of the LED (off/on)


/*-----( setup temp/humidity sensor )-----*/


#define RELAY_ON 0                /*  compensate for relay backwardness*/    
#define RELAY_OFF 1               /*  compensate for relay backwardness*/    


//#def MEGA
#define YP A2                    /* must be an analog pin, use "An" notation!*/
#define XM A1                    // must be an analog pin, use "An" notation!
#define YM 54                    // can be a digital pin, this is A0
#define XP 57                    // can be a digital pin, this is A3
#define TS_MINX 140
#define TS_MAXX 900
#define TS_MINY 120
#define TS_MAXY 940
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// The 2.8" TFT Touch shield has 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);


/*----( SETUP: RUNS ONCE )----*/
void setup()  
{
  Tft.TFTinit();
  //Tft.setDisplayDirect(DOWN2UP);
  // Tft.setDisplayDirect(UP2DOWN);
  Tft.setDisplayDirect(LEFT2RIGHT);


  //-------( Initialize Pins so relays are inactive at reset)----*/
  digitalWrite(32, RELAY_OFF);
  digitalWrite(34, RELAY_OFF);
  digitalWrite(36, RELAY_OFF);
  digitalWrite(38, RELAY_OFF);
  digitalWrite(40, RELAY_OFF);  
  digitalWrite(42, RELAY_OFF);
  digitalWrite(44, RELAY_OFF);
  digitalWrite(46, RELAY_OFF);
  //---( THEN set pins as outputs )----*/

  pinMode(32, OUTPUT);  
  pinMode(34, OUTPUT);  
  pinMode(36, OUTPUT);  
  pinMode(38, OUTPUT);  
  pinMode(40, OUTPUT);  
  pinMode(42, OUTPUT);  
  pinMode(44, OUTPUT);  
  pinMode(46, OUTPUT);
  delay(400); /*---( Check that all relays are inactive at Rese)----*/

  Serial.begin(57600);   /*---(  )----*/
  Draw_Button_Frames();
  Fill_Buttons();
 

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{

  Read_TS();

}

//////////////////////////////////////////////////
void Read_TS(){
  // a point object holds x y and z coordinates
  Point p = ts.getPoint();
  if (p.z > ts.pressureThreshhold) {
  }
  p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);
  p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);
  if (p.z > ts.pressureThreshhold) {
    Serial.print("X = ");
    Serial.println(p.x);
    Serial.print("\tY = ");
    Serial.println(p.y);
  }
  ///////////////////////////////////
  if (p.y > 1 && p.y < 45 && p.x > 200 && p.x < 220) {
    //toggle the state of the LED
    if (LED_1_State == HIGH){
      digitalWrite(32, RELAY_OFF);
      Tft.fillCircle(219, 30, 16,RED);
      Serial.print("LED_1_State = ");
      Serial.println(LED_1_State);
      LED_1_State = LOW;
    }
    else {
      digitalWrite(32, RELAY_ON);
      Tft.fillCircle(219, 30, 16,GREEN);
      Serial.print("LED_1_State = ");
      Serial.println(LED_1_State);
      LED_1_State = HIGH;
    }

    Serial.println("Button 1 Pressed");  
  }
  ///////////////////////////////////////////
  if (p.y > 49 && p.y < 79 && p.x > 200 && p.x < 220) {
    //toggle the state of the LED
    if (LED_2_State == HIGH){
      digitalWrite(34, RELAY_ON);
      Tft.fillCircle(219, 75, 16,GREEN);
      LED_2_State = LOW;
    }
    else {  
      Tft.fillCircle(219, 75, 16,RED);
      LED_2_State = HIGH;
      digitalWrite(34, RELAY_OFF);

    }
    Serial.println("Button 2 Pressed");  
  }  
  ///////////////////////////////////////////  
  if (p.y > 94 && p.y < 130 && p.x > 200 && p.x < 220){    
    //toggle the state of the LED
    if (LED_3_State == HIGH){
      digitalWrite(36, RELAY_ON);
      Tft.fillCircle(219, 120, 16,GREEN);
      LED_3_State = LOW;  
    }
    else {  
      Tft.fillCircle(219, 120, 16,RED);
      LED_3_State = HIGH;
      digitalWrite(36, RELAY_OFF);

    }
    Serial.println("Button 3 Pressed");  
  }  
  ///////////////////////////////////////////
  if (p.y > 150 && p.y < 176 && p.x > 200 && p.x < 220){
    //toggle the state of the LED
    if (LED_4_State == HIGH){
      digitalWrite(38, RELAY_ON);
      Tft.fillCircle(219, 165, 16,GREEN);
      LED_4_State = LOW;
    }
    else {  
      Tft.fillCircle(219, 165, 16,RED);
      LED_4_State = HIGH;
      digitalWrite(38, RELAY_OFF);

    }
    Serial.println("Button 4 Pressed");  
  }  
  ///////////////////////////////////////////
  if (p.y > 190 && p.y < 220 && p.x > 205 && p.x < 240){
    //toggle the state of the LED
    if (LED_5_State == HIGH){
      digitalWrite(40, RELAY_ON);
      digitalWrite(42, RELAY_ON);  
      Tft.fillCircle(219, 210, 16,GREEN);
      LED_5_State = LOW;
    }
    else {  
      Tft.fillCircle(219, 210, 16,RED);
      LED_5_State = HIGH;
      digitalWrite(40, RELAY_OFF);
      digitalWrite(42, RELAY_OFF);
    }

    Serial.println("Button 5 Pressed");  
  }    

  if (p.y > 240 && p.y < 270 && p.x > 205 && p.x < 240){
    if (LED_6_State == HIGH){
      digitalWrite(44, RELAY_ON);
      Tft.fillCircle(219, 255, 16,GREEN);
      LED_6_State = LOW;
    }
    else {  
      Tft.fillCircle(219, 255, 16,RED);
      LED_6_State = HIGH;
      digitalWrite(44, RELAY_OFF);
    }
    //Serial.println("Button 6 Pressed");  
  }    

  if (p.y > 280 && p.y < 325 && p.x > 5 && p.x < 225){
    digitalWrite(32, RELAY_OFF);
    digitalWrite(34, RELAY_OFF);
    digitalWrite(36, RELAY_OFF);
    digitalWrite(38, RELAY_OFF);
    digitalWrite(40, RELAY_OFF);
    digitalWrite(42, RELAY_OFF);
    digitalWrite(44, RELAY_OFF);
    digitalWrite(46, RELAY_ON);

    Tft.fillCircle(219, 30, 16,RED);
    Tft.fillCircle(219, 75, 16,RED);
    Tft.fillCircle(219, 120, 16,RED);    
    Tft.fillCircle(219, 165, 16,RED);
    Tft.fillCircle(219, 210, 16,RED);
    Tft.fillCircle(219, 255, 16,RED);  
    Serial.println("Button 7 Pressed");  
  }    

}


///////////////////////////////////////////////////////
void Draw_Button_Frames(){
  /*---( Draw Button Frames )----*/
  /*---( Button 1 )----*/
  Tft.drawCircle(219, 30, 17,BLUE);
  Tft.drawCircle(219, 30, 18,BLUE);
  Tft.drawCircle(219, 30, 19,BLUE);
  Tft.drawCircle(219, 30, 20,BLUE);
  /*---( Button 2 )----*/
  Tft.drawCircle(219, 75, 17,BLUE);
  Tft.drawCircle(219, 75, 18,BLUE);
  Tft.drawCircle(219, 75, 19,BLUE);
  Tft.drawCircle(219, 75, 20,BLUE);
  /*---( Button 3 )----*/
  Tft.drawCircle(219, 120, 17,BLUE);
  Tft.drawCircle(219, 120, 18,BLUE);
  Tft.drawCircle(219, 120, 19,BLUE);
  Tft.drawCircle(219, 120, 20,BLUE);
  /*---( Button 4 )----*/
  Tft.drawCircle(219, 165, 17,BLUE);
  Tft.drawCircle(219, 165, 18,BLUE);
  Tft.drawCircle(219, 165, 19,BLUE);
  Tft.drawCircle(219, 165, 20,BLUE);
  /*---( Button 5 )----*/
  Tft.drawCircle(219, 210, 17,BLUE);
  Tft.drawCircle(219, 210, 18,BLUE);
  Tft.drawCircle(219, 210, 19,BLUE);
  Tft.drawCircle(219, 210, 20,BLUE);
  /*---( Button 6 )----*/
  Tft.drawCircle(219, 255, 17,BLUE);
  Tft.drawCircle(219, 255, 18,BLUE);
  Tft.drawCircle(219, 255, 19,BLUE);
  Tft.drawCircle(219, 255, 20,BLUE);  

}

/////////////////////////////////////////////////////////////////////
 void Fill_Buttons(){
    Tft.fillCircle(219, 30, 16,RED);
    Tft.fillCircle(219, 75, 16,RED);
    Tft.fillCircle(219, 120, 16,RED);
    Tft.fillCircle(219, 165, 16,RED);
    Tft.fillCircle(219, 210, 16,RED);
    Tft.fillCircle(219, 255, 16,RED);
  }



3  Using Arduino / Project Guidance / Re: Lizard Brain on: August 27, 2013, 06:43:36 pm
I brought  the wheelchair base into the shop and decided to cut the plugs off and start spinning the motors. Encountering locked rotor amperage and no movement I started breaking down one the motors. It was full of rust and frozen in place. After applying a liberal application of deep creep, I pulled the other motor and gave it the same treatment. One good whack with the plastic hammer and they came apart. To the wire wheel with the rotors. Then with a sandpaper wrapped broomstick the magnets were almost pristine. Four new bearings later the motors are purring. I did inspect the gearboxes and found no water in them.

The Kangaroo x2  is in. After some driver issues I got it running on my desk. The encoders are attached and coupled to the motors. It  needs improvement but it will do "for testing purposes". And the gearboxes and wheels are safely in a tote.

The original questions were indeed answered by the kangaroo x2.

The next dilemma is how to implement a two way switch to supply the packetized serial data to the kangaroo from the laptop and I have decided to use an  R/C transmitter/receiver for teach mode.....so the Arduino now has to be the Lizard Brain, Pass data from computer via USB and interpret 2 channels of R/C.

I may have to move to the Mega to accomplish all of this just from a program space considerations.

Any thoughts / discussions?
4  Using Arduino / Project Guidance / Re: Lizard Brain on: August 17, 2013, 05:37:03 pm
Still no Kangaroo. Maybe next week. Which brings another point.
I want the command from the laptop to be forwarded to the drive but if the laptop is off (low battery) the arduino enters seek nest behavior. I considered just using a relay to switch the TX and RX lines from laptop to microcontroller but serial comms would have to be reestablished after the switch so I think i will need a more robust solution. But I will try it when the kangaroo comes in.
5  Using Arduino / Project Guidance / Re: Lizard Brain on: August 16, 2013, 10:48:12 am
Quote
Are the motors just two lead DC motors, not brushless? If so, it seems to me you only need to open one lead with an E-stop. Please correct me if I'm wrong.

Yes brushed DC Motors but there are 2 motors hence a dual switch to disable both motors.

6  Using Arduino / Project Guidance / Re: Lizard Brain on: August 15, 2013, 06:34:43 pm
The Next discussion would be Fusing and E-stops.

From Dimension Engineering:
Quote
We prefer that you fuse the motors rather than the battery leads, or if for safety reasons you need to fuse the battery that you do it at a much higher current than the motors. The reason is this:

Because Sabertooth is a regenerative driver, it relies on having a battery to put regenerated energy back into when you command a stop (and at other times). If you draw enough power to blow a battery fuse, all of a sudden the Sabertooth has nowhere to put the energy. It will see the fault, though, and try to stop the motor. It doesn't, however, have anywhere to put the energy (the mechanical energy of the vehicle and the electrical energy carried in the windings and the caps). So blowing a battery fuse will sometimes kill the driver -- which we would replace under warranty, but it's still annoying for all parties.

The better way to do it is to fuse the motor leads. If a motor fuse blows, the motor will freewheel, the Sabertooth will sit there contentedly, and the only thing you will have to replace is the fuse. A very large fuse (100 amps) on the battery lead will protect the wiring in the event of a battery lead short or motor driver failure.

This appears to handle fusing unless there are any other opinions.

E-Stop:
So killing the power to the Sabertooth is a bad thing but the motor circuit  could be broken giving me a simple but expensive option of a dual 60 amp switch or relay if this practice will not bruise the controller.

Being as I will probably be using Packetized mode Any other E-Stop will be generated by software. This is bad practice in the industrial world and could be bad on a large rover.


 


7  Using Arduino / Project Guidance / Re: Lizard Brain on: August 13, 2013, 07:33:08 pm
Quote
What is 'Primary/Secondary relationship'?
Master/Slave if you like. Driving one wheel and matching the speed with the other wheel.

It looks like the Kangaroo x2 may take care of it

Quote
I'd expect the digital approach to be more accurate, but you will need to decide your own trade-off between how well it works and how easy it is to implement.

I concur with your assessment but was throwing it out to see if anyone would argue for analog.

8  Using Arduino / Project Guidance / Lizard Brain on: August 12, 2013, 06:40:05 pm
I am building a low level  Uno based Differential Steering Robot Motion Base. Everything is oversized because this is going into an Electric Wheelchair robot. I
 have:
1 Sabertooth 2 x 60 (dual motor 60 Amp)
1 Kangaroo x2 motion controller.
2 Very nice Dynopar Quadrature Encoders.
4 Sharp IR ranging units(2 long and 2 short range)
4 Scanner mounts with servos for IR units
1 IMU (compass , Roll , Tilt , Yaw)
1 Arduino Uno
2 Small 24 volt gearmotor driven O-Ring Wheels
2 Rechargable 15 Volt Battery Packs and Charger
1 Small Tail-Dragger Robot Platform.
1 Large 24 Volt Electric Wheelchair Base.

My Goals:
Monitor Battery, On low battery FIND NEST using just the UNO
Wander using non-contact IR bumpers  using just the UNO
Monitor Contact Sensors  using just the UNO
Wall Follow  using just the UNO
Beacon Seeking (Find Nest)  using just the UNO


Receive Motion Commands Serially from laptop(Drive, Turn, Distance, etc.) as high level commands from Roborealm and/or FlowStone


Where Am I at:
Manually Charging Batteries
Rudimentary Driving controls.
Sabertooth run in Analog Mode.
Sabertooth run in Simple Serial
Sabertooth run in Paketized mode
Kangaroo x2 ordered.
Rudimentary Wandering code using Sharp sensors mounted on servos  to scan for obstacles.
Moving Sabertooth S1 fsrom TX pin to Pin 2 To restore serial coms to PC
IMU Examples up and running doing Telemetry back to PC

Discussion:
How to Implement Primary/Secondary relationship for motor speed.
The first question is analog or Digital motor feedback.




9  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 24, 2013, 09:58:26 am
Quote
You don't need to initialise it at all - it is static, so the compiler makes it zero, unless you tell it otherwise.
But you do need to update it.

Code:
static unsigned long lastTick = 0;
So something more like
Code:
static unsigned long lastTick = millis();
10  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 24, 2013, 09:34:46 am
Is there a way to stay in the loop without using delay I do want to be able to service sensors while counting out the stir time?
11  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 24, 2013, 09:28:29 am
Quote
bigger hint:



 
Code:
if (millis() - 0 >= 1000)

I am confused by this code. I have it working elsewhere. It counts 1000 millisec and increments the second variable.
But, I think I am tracking that  millis() returns a rather large number (elapsed time) and - 0 it is still >= 1000.
So I need to initialize
Code:
static unsigned long lastTick = 0;
this differently?
12  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 03:43:39 pm
Quote
It's an understandable side-effect of cross-posting.
Actually I posted a new question because I was receiving critique instead of help. Seems there is no shortage of people to tell you you are doing it wrong, and only a few pathfinders.
13  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 23, 2013, 03:23:44 pm

Quote
What does it do? What would you like it to do? What serial output do you get?

Since you're calling it in loop, I assume you're expecting it to spool up for a 10 second stir and then wind down and stop and then do it all again repeatedly. If that's the case but it only works once, the likely cause is that you never set you second variable back to zero. After the wind down would be a good place.

for this example that is exactly what i want it to do

This is what it is doing.
motorspeed = 176
motorspeed = 177
motorspeed = 178
motorspeed = 179
motorspeed = MAX 25
Brake On motorspeed = 0
motorspeed = 1
motorspeed = 2
motorspeed = 3
motorspeed = 4
motorspeed = 5
motorspeed = 6
 It never reaches the timer or the ramp down.






Quote
Every time the stir() function is called the stir speed will return to zero then ramp up.  Is that what you want ?  Do you want the program to stay in the stir() function for 10 seconds or for it to check each time that it is called whether it should ramp up the speed or whether it is time to ramp down the stir speed if it is running at full speed and has been for 10 seconds ?
I want to call the stir() function passing a duration in seconds ..ramp up count to the variable passed ... then ramp down and then exit the function. I want to stay in the function until the ramp down is complete.
14  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 03:02:49 pm
Yup, Still wrestling with this issue. I seem to get comments and criticisms instead of help.
15  Using Arduino / Programming Questions / Re: Not Enough Analog Out pins on: April 23, 2013, 02:43:10 pm
But this is a small issue on the butt of a larger problem.

Motor Acceleration Timer Deceleration Problem
http://arduino.cc/forum/index.php/topic,162373.msg1213468.html#msg1213468
Pages: [1] 2 3 ... 5