Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Seek seeks, it does not read ;)
22
Hi Davidrh.
In my drawing there is a capacitor between 5v and ground, but I don't known where you mean for the other one. Could you read my drawing better now? I was looking at the spec for the shift register and may be I am wrong but it said 500ma per output. Do I have to write you sketch out or is there a way to copy it to my Ardunio
Eddie
23
Project Guidance / Arcade Claw Machine
Last post by lostarduino - Today at 07:49 am
I would like to control a digital potentiometer using Arduino and step voltage from 20v to 27v at set ratio. I am trying to retrofit a claw machine to a win ratio from a constant set voltage, so that when people play, lets say 1 through 5 tries the voltage will be set to maximum. I am open to any ideas or different ways to go about this.

Thanks!
24
No idea where you found that quote - if it was ever the case, it dates to eons ago.
I've been baffled by the same quote for a while.

It's here, in arduino.cc's page about the Nano.
25
I want the count to reach 2 then reset to 0 and go to void START, fixed that already, but what I meant was that for every "tick" that I make with the encoder, for every ONE rotation, it adds multiple values to "x" instead of just adding one, thus it practically skips menus 1 and -1 and goes directly to 2, -2 or START.

Edit: Fixed the blinking, thanks :). Now the only problem is the "random" X value
Code:
Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
volatile int x = 0;
//int ostatniStan = 0;
//int obecnyStan = 0;
int cleanOnce = 0;
int pinA = 2;
int pinB = 3;


void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(pinA,INPUT);
  pinMode(pinB,INPUT);
  START();
//  ostatniStan = digitalRead(pinA);
  attachInterrupt(digitalPinToInterrupt(2), interrupts1, CHANGE);
 

 
}

void loop()
{
  switch(x)
  {
    case -1:
    {
      ADB2849_50();
      break;
    }
    case -2:
    {
      ADB3740SX();
      break;
    }
    case 1:
    {
      ADB5720SX();
      break;
    }
    case 2:
    {
      HDS();
      break;
    }
   break;
  }
  if (x >= 2 || x <= -2)
  {
    x = 0;
    START();
  }
}
void START()
{
  lcd.setCursor(1, 0);
  lcd.print("Wybierz opcje:");
  lcd.setCursor(0, 1);
  lcd.print("<2849_50");
  lcd.setCursor(9, 1);
  lcd.print("5720SX>");
}

void ADB2849_50()
{
  cleanOnce = 0;
  if (cleanOnce == 0)
  {
    lcd.clear();
    cleanOnce = 1;
  }
  lcd.setCursor (3, 0);
  lcd.print("ADB2849_50");
  lcd.setCursor (0, 1);
  lcd.print("<3740SX");
  lcd.setCursor (10, 1);
  lcd.print("START>");
}
void ADB3740SX()

  cleanOnce = 0;
  if (cleanOnce == 0)
  {
    lcd.clear();
    cleanOnce = 1;
  }
  lcd.setCursor (4, 0);
  lcd.print("ADB3740SX");
  lcd.setCursor (8, 1);
  lcd.print("2849_50>");
  lcd.setCursor (0, 1);
  lcd.print("<START");
}
void ADB5720SX()
{
  cleanOnce = 0;
  if (cleanOnce == 0)
  {
    lcd.clear();
    cleanOnce = 1;
  }
  lcd.setCursor (3, 0);
  lcd.print("ADB5720SX");
  lcd.setCursor (11, 1);
  lcd.print("HDS>");
  lcd.setCursor (0, 1);
  lcd.print("<START");
}

void HDS()
{
  cleanOnce = 0;
  if (cleanOnce == 0)
  {
    lcd.clear();
    cleanOnce = 1;
  }
  lcd.setCursor (6, 0);
  lcd.print("HDS");
  lcd.setCursor (0, 1);
  lcd.print("<5720SX");
  lcd.setCursor (10, 1);
  lcd.print("START>");
}


void interrupts1()
{
  //obecnyStan = digitalRead(pinA);
  //if (obecnyStan != ostatniStan)
  //{
  //  if (digitalRead(pinB) != obecnyStan)
  //  {
  //    x++;
  //    Serial.println(x);
  //  }
  //  else
  //  {
  //    x--;
  //    Serial.println(x);
  //  }
  //}
  //ostatniStan = obecnyStan;
  if (digitalRead(pinA) != digitalRead(pinB))
  {
    x++;
    Serial.println(x);
  }
  else
  {
    x--;
    Serial.println(x);
  }
}
//}
26
CAIR?
27
I'm fairly new to arduino, I've dabbled with it here and there but I'm working on my biggest project yet and need some assistance getting it to work properly.  Basically I have a touchscreen with a virtual numberpad and start/stop buttons on it, I want to be able to take the input from the numberpad and change the amount of time between each time the motor runs (so input 5000 on the number pad and the motor will output the set amount of steps every 5 seconds). That's the first issue.

The second issue, and the most important is this; I want the motor to start running once the start button is pressed on the touchscreen and to stop once when the "stop" button is pressed. So far I have been able to get the motor to take the inputted amount of steps once when the button is pressed (in this case I have it set to take 25 steps). I believe this issue could be solved with a while loop but I have no idea how to implement it into this situation.

For reference I am using an Elegoo 2.8" TFT touch screen and I have modified one of the default example programs that comes with it to fit my needs.

TL;DR: I want the number pad on the touchscreen to control the length of the delay between steps, and when I press the start button I want the motor to run until I press the stop button.


Code: [Select]

void setup(void) {

     // Sets the two pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

#ifdef USE_Elegoo_SHIELD_PINOUT
  Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = tft.readID();
  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  }else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if(identifier==0x0101)
  {    
      identifier=0x9341;
       Serial.println(F("Found 0x9341 LCD driver"));
  }else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_Elegoo_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier=0x9341;
  
  }

  tft.begin(identifier);
  tft.setRotation(2);
  tft.fillScreen(BLACK);
  
  // create buttons
  for (uint8_t row=0; row<5; row++) {
    for (uint8_t col=0; col<3; col++) {
      buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
                 BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
                  BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
                  buttonlabels[col + row*3], BUTTON_TEXTSIZE);
      buttons[col + row*3].drawButton();
    }
  }
  
  // create 'text field'
  tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);

 
}
// Print something in the mini status bar with either flashstring
void status(const __FlashStringHelper *msg) {
  tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
  tft.setCursor(STATUS_X, STATUS_Y);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.print(msg);
}
// or charstring
void status(char *msg) {
  tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
  tft.setCursor(STATUS_X, STATUS_Y);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(1);
  tft.print(msg);
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop(void) {
  /*TSPoint p;
  p = ts.getPoint();
  */
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  
 // p = ts.getPoint();
  /*
  if (ts.bufferSize()) {
    
  } else {
    // this is our way of tracking touch 'release'!
    p.x = p.y = p.z = -1;
  }*/
  
  // Scale from ~0->4000 to tft.width using the calibration #'s
  /*
  if (p.z != -1) {
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    Serial.print("("); Serial.print(p.x); Serial.print(", ");
    Serial.print(p.y); Serial.print(", ");
    Serial.print(p.z); Serial.println(") ");
  }*/
   if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = (tft.height()-map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
   }
  
  // go thru all the buttons, checking if they were pressed
  for (uint8_t b=0; b<15; b++) {
    if (buttons[b].contains(p.x, p.y)) {
      //Serial.print("Pressing: "); Serial.println(b);
      buttons[b].press(true);  // tell the button it is pressed
    } else {
      buttons[b].press(false);  // tell the button it is NOT pressed
    }
  }

  // now we can ask the buttons if their state has changed
  for (uint8_t b=0; b<15; b++) {
    if (buttons[b].justReleased()) {
      // Serial.print("Released: "); Serial.println(b);
      buttons[b].drawButton();  // draw normal
    }
    
    if (buttons[b].justPressed()) {
        buttons[b].drawButton(true);  // draw invert!
        
        // if a numberpad button, append the relevant # to the textfield
        if (b >= 3) {
          if (textfield_i < TEXT_LEN) {
            textfield[textfield_i] = buttonlabels[b][0];
            textfield_i++;
    textfield[textfield_i] = 0; // zero terminate
            
           // fona.playDTMF(buttonlabels[b][0]);
          }
        }

        // clr button! delete char
        if (b == 1) {
          
          textfield[textfield_i] = 0;
          if (textfield > 0) {
            textfield_i--;
            textfield[textfield_i] = ' ';
          }
        }

        // update the current text field
        Serial.println(textfield);
        tft.setCursor(TEXT_X + 2, TEXT_Y+10);
        tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
        tft.setTextSize(TEXT_TSIZE);
        tft.print(textfield);

        // start motor
        if (b == 0) {
        
           digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
           // Set pulses (25+) for how much you want the motor to move each time)
           for(int x = 0; x < 25; x++) {
          digitalWrite(stepPin,HIGH);
          delayMicroseconds(1000);
          digitalWrite(stepPin,LOW);
          delayMicroseconds(1000);

          delay(5000); //this delay is what I want to be able to change with the numberpad
       }
      
          status(F("Starting motor"));
          Serial.print("Starting motor"); Serial.print(textfield);
          
          //fona.callPhone(textfield);
          
        }

         // stop motor
        if (b == 2) {
        
          digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
          // Set pulses (25+) for how much you want the motor to move each time)
          for(int x = 0; x < 25; x++) {
         digitalWrite(stepPin,LOW);
         delayMicroseconds(1000);
         digitalWrite(stepPin,LOW);
         delayMicroseconds(1000);
      }
          
          status(F("Stopping motor"));
          //fona.hangUp();
        }
        
      delay(100); // UI debouncing
    }
  }
  
}

28
file.seek(pos)
Returns, true for success, false for failure (boolean)
29
General Electronics / Re: NiZn batteries?
Last post by srnet - Today at 07:31 am
1) 1.85V is OPEN CIRCUIT. It is quite probably that it is 1.8V or less when connected.
I was just measuring one of my 'projects' it contains several 3.6V maximum rated devices.

The 'project' spends large amounts of time (more than 95%) in sleep mode and the measured current is then from 35uA to 200uA.

I would suggest that a high current capability battery is going to see my 'project' as open circuit.

30
Programming Questions / Wireless 2 position servo
Last post by zenixnet - Today at 07:26 am
Hello all,
I'm trying to make a contraption where you press a button on one board and it moves the servo either to 90 degrees or 180 degrees. If it's at 90 then it moves to 180 and vice versa. I'm not very knowledgeable when it comes to this stuff as this is my first major project so bear with me. I already have the wireless system working (thanks to hours of Googling) and a toggle system for an LED (for testing to see if the wireless is working). I'm using one of the tiny RF transmitters, two Nano's, and a servo from radio shack. Here is the code for the receiver end of things:

Code: [Select]
#include <VirtualWire.h>
#include <ServoTimer2.h>
const int releu_pin = 9;
const int servoPin = 6;
const int transmit_pin = 12;
const int receive_pin = 3;//pin connected between RX module and Arduino
const int transmit_en_pin = 5;

ServoTimer2 myservo; 

void setup()
{
    myservo.attach(servoPin);
    myservo.write(90);
    //delay(1000);
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_en_pin);
    vw_set_ptt_inverted(true);
    vw_setup(2000);//speed communication bps

    vw_rx_start();       // activate receiving mode

    pinMode(releu_pin, OUTPUT);
   
   
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen))  //verify if any data is received
    {
      if(buf[0]=='1')//if received 1 turn ON releu_pin
      {
        myservo.write(180);
        digitalWrite(releu_pin , HIGH);
        //delay(15);
      } 
     if(buf[0]=='0')
     {
        myservo.write(90);
        digitalWrite(releu_pin , LOW);
        //delay(15);
    }
  }
}


 
Pages: 1 2 [3] 4 5 ... 10