Recent Posts

Pages: [1] 2 3 ... 10
1
Programming Questions / Re: LCD types "infinite"
Last post by RayLivingston - Today at 03:57 pm
This

Code: [Select]

volt=((5/1024)*(float)sound);


will ALWAYS be zero.  5/1024 will always == 0.  Try:

Code: [Select]

volt=(5.0 * (float)sound)/1024.0);


Regards,
Ray L.
2
That's not a schematic.

But I'm still 99% certain it won't work with 4051. It's not an rf frequency component.
3
Project Guidance / Re: Sending GPS cordinates aft...
Last post by /dev - Today at 03:44 pm
You have a Mega, so you should use the extra HardwareSerial ports, Serial1, Serial2 or Serial3.  This GSM-GPRS-GPS-Shield-GSMSHIELD library (great name!) will use Serial1 for the GSM shield if you change these lines at the top of GSM.h:

Code: [Select]
//#define UNO
#define MEGA

Then make sure the GSM TX is connected to RX1 (Mega pin 19), and the GSM RX is connected to TX1 (Mega pin 18).

You should connect the GPS to either Serial2 (GPS TX to Mega RX2 pin 17) or Serial3 (GPS TX to Mega RX3 pin 15).  DO NOT USE SoftwareSerial.

Quote from: senoyasha
I'm trying to send the GPS coordinates via SMS but only after receiving a keyword "TRACK". I want it to send continuously every a minute or so, only after receiving the said keyword.
First, declare a tracking flag that can be true or false:

    bool tracking = false;

Then set the flag when you receive "TRACK".  Shouldn't you be able to stop tracking?  Maybe clear the flag when you receive "STOP":

Code: [Select]
    char smsAvailable = sms.IsSMSPresent( SMS_UNREAD );

    if (smsAvailable > 0) {
      // Got one!
      char message[ 20 ];

      sms.GetSMS( smsAvailable, remoteNumber, sizeof(remoteNumber), message, sizeof(message) );

      if (strstr_P( message, (const char *) F("TRACK") ))
        tracking = true;
      else if (strstr_P( message, (const char *) F("STOP") ))
        tracking = false;

      sms.DeleteSMS( smsAvailable );
    }

Quote
Also I'm trying to light a LED if there is a location fix
Don't use delay.  It will cause the sketch to lose GPS data.  Just set the LED on or off when a new fix is received:

Code: [Select]
  // Check for GPS data
  while (gps.available( gps_port ))
  {
    fix = gps.read();
    gpsSeconds++; // this is our "clock" for timing, like millis()

    // Turn the pin 5 LED ON or OFF, depending on whether we have a fix or not.
    digitalWrite( 5, fix.valid.location );

Incorporating all those suggestions, here is a new sketch:

Code: [Select]
static const bool useSMS = false; // when false, don't send or receive SMS messages, just print

#include <SIM900.h>
#include "sms.h"
SMSGSM sms;

#undef STATUS_NONE // bad SIM900 library!
#include <NMEAGPS.h>
NMEAGPS gps;
gps_fix fix;

#define gps_port Serial2 // pin 17 to GPS TX, pin 16 to GPS RX


char remoteNumber[] = "+639059456422";


void setup()
{
  Serial.begin(9600);
  gps_port.begin(9600);
  if (useSMS)
     gsm.begin(9600); // connect to Serial1 (pin 19 to GPS TX, pin 18 to GPS RX)
}

uint16_t gpsSeconds;
bool     tracking = false;
uint16_t lastTrackSent;
uint16_t lastSMScheck;

void loop()
{
  // Check for a command from the Serial Monitor window
  //    (just for debugging, really).
  if (Serial.available()) {
    char cmd = Serial.read();

    if (cmd == 't') {
      tracking = true;
      Serial.println( F("Tracking ON") );
    } else if (cmd == 's') {
      tracking = false;
      Serial.println( F("Tracking OFF") );
    }
  }
 
  // Check for GPS data
  while (gps.available( gps_port ))
  {
    fix = gps.read();
    gpsSeconds++; // this is our "clock" for timing, like millis()

    // Turn the pin 5 LED ON or OFF, depending on whether we have a fix or not.
    digitalWrite( 5, fix.valid.location );

    // Don't constantly send a tracking SMS, because it takes a long time.
    //    Just send it once every 60 seconds.

    if (fix.valid.location && tracking &&
        ((gpsSeconds - lastTrackSent) > 1 * 60))
    {
      Serial.print( F("longitude: ") );
      Serial.println( fix.latitude(), 5 );
      Serial.print( F("latitude : ") );
      Serial.println( fix.longitude(), 5 );
      Alert();

      lastTrackSent = gpsSeconds; // reset the timer
    }
  }

  // Don't constantly check for an SMS, because it takes a long time.
  //    Just check once every 30 seconds.

  if (useSMS && ((gpsSeconds - lastSMScheck) > 30)) {

    // Time to check for a new SMS
    char smsAvailable = sms.IsSMSPresent( SMS_UNREAD );

    if (smsAvailable > 0) {
      // Got one!
      char message[ 20 ];

      sms.GetSMS( smsAvailable, remoteNumber, sizeof(remoteNumber), message, sizeof(message) );

      if (strstr_P( message, (const char *) F("TRACK") ))
        tracking = true;
      else if (strstr_P( message, (const char *) F("STOP") ))
        tracking = false;

      sms.DeleteSMS( smsAvailable );
    }

    lastSMScheck = gpsSeconds;
  }

} // loop

void Alert()
{
  // Build the message to send
  char text[ 159 ];

  strcpy_P( text, (const char *) F("Current Motorcycle Location\nlongitude: ") );
  char *ptr = &text[ strlen(text) ]; // end of the text so far

  if (fix.valid.location)                 //  <-- add this if test
    dtostrf( fix.latitude(), 4, 5, ptr ); // append the latitude
  char   *lat    = ptr;                 // remember where these characters are...
  size_t  latLen = strlen(ptr);         //   ... and how many.
  ptr = &ptr[ latLen ];

  strcpy_P( ptr, (const char *) F("\nlongitude: ") ); // append this string
  ptr = &ptr[ strlen(ptr) ];

  if (fix.valid.location)                 //  <-- add this if test
    dtostrf( fix.longitude(), 4, 5, ptr ); // append the longitude
  char   *lon    = ptr;                  // remember...
  size_t  lonLen = strlen(ptr);
  ptr = &ptr[ lonLen ];

  strcpy_P( ptr, (const char *) F("\n\nOpen Google Maps by clicking:\nhttps://maps.google.com/maps?q=(") );
  ptr = &ptr[ strlen(ptr) ];

  strncpy( ptr, lat, latLen );  // copy those latitude characters again
  ptr = &ptr[ latLen ];

  *ptr++ = ',';  // append one character

  strncpy( ptr, lon, lonLen );  // copy those longitude characters again
  ptr = &ptr[ lonLen ];

  strcpy_P( ptr, (const char *) F(")") ); // and finish the URL


  //  Make sure we didn't run past the end of the text[array]
  size_t textLen = strlen(text);
  if (textLen >= sizeof(text)) {
    Serial.print( F("text array too small!  Needs to be at least text[") );
    Serial.print( textLen + 1 );
    Serial.println( F("] !") );
  }

  Serial.println( text );

  if (useSMS) {
    //  Send the message

    if (sms.SendSMS( remoteNumber, text ))
      {
      Serial.println( F("\nSMS sent OK.") );
      }
    else
      {
      Serial.println( F("\nError sending SMS.") );
      }
  }

} // Alert

I added a useSMS flag that lets you test the program without sending or receiving messages.  You can use the Serial Monitor window to enter a command.  Enter 't' to start tracking or 's' to STOP tracking.  When useSMS is false, it will just print things to the Serial Monitor window.  No SMS will be sent.  Change useSMS to true when you want to use the GSM shield to send/receive SMS messages.

As I mentioned in your other post, "the SIM900 library has several compile warnings, and it does not play nicely with other libraries."  Everytime you use one of the SIM900 library methods, it will lose GPS data.  When the SIM900 library returns to loop, it will eventually start getting fixes again.

With the timings you are using (1 minute), the sketch will work.  Just remember that after performing an SMS operation, it may take 1 or 2 seconds to get the current GPS fix.

Cheers,
/dev
4
5
Software / Copia di una Mifare Classic da...
Last post by alee81m - Today at 03:43 pm
Buongiorno a tutti,
Mi occupo di domotica alberghiera ed in particolare di serrature elettroniche e controlli accesso.
Da circa 2 anni il produttore ha cambiato sistema passando dalle tessere Mifare classic 1k (alta frequenza 13,56mhz) al sistema temic (125khz) più economico e secondo me molto meno sicuro.
Da circa un anno il produttore non mi fornisce più neanche le tessere Mifare, ma dato che la quasi totalità dei miei clienti ha dispositivi compatibili solo Mifare, mi ha fornito un software che mi consente di formattare le tessere acquistate altrove rendendole compatibili col sistema utilizzato.
Il problema è che ho 4 software gestionali, di cui nessuno è compatibile con gli altri (per utilizzare il software 1 devo necessariamente caricare il firmware 1 sulle serrature del cliente), ed il software di formattazione tessere che mi ha fornito funziona su 3 software ma non sul 4° (di cui lo stesso produttore dice che acquistava le tessere già pre-formattate e non sa darmi informazioni).
Ora ho la necessità di poter replicare queste tessere formattate (nelle quali sono impostate solo le password di cui il fornitore mi ha messo a conoscenza, e non ci sono dati che consentono apertura, lettura dati o qualsiasi altra operazione). Per ulteriore conferma della mia legittimità in quest'utilizzo, e dell'utilizzo lecito che ne devo fare, posso fornire agli admin sia le password che tutti gli altri dati, non chè i miei dati personale e aziendali (che tuttavia non pubblico per evitare problemi di sicurezza ai miei clienti)

Ho fatto diverse prove con Arduino Uno + modulo RC522 ma mancandomi le conoscenze di programmazione sono in alto mare
6
Français / Re: Analogue Read problème
Last post by maxh96 - Today at 03:42 pm
j'avais trouvé merci. Il était donc possible de faire plusieurs tone en même temps ! Pas besoins de prendre de haut donc en disant qu'il n'est pas possible plusieurs fois! Merci quand même  8) 
7
Sensors / Re: Problem with Pulse counter...
Last post by cattledog - Today at 03:42 pm
Quote
can ignore everything to do with the digitalReadCount as I am using the sensor_isr method.  Is that correct?
Yes.

The two methods were just for testing to help understand the erratic counts and the noise problems.
8
Hi,
I have a multiple slaves (4 addresses) device in which the Read line (SDR) has been split into 2 separate lines;
The purpose of the separation is to achieve full galvanic separation (this is a very old device).

The clock is via optocoupler.
The master to slave data Write is via optocoupler master to slave.
The slave to master data Read is via optocoupler slave to master, on a separate line, as can be seen in the attached drawing.

I need to design a new master to control the slaves and read data.
With standard I2C (common data line) this would not be a problem using the controller hardware I2C and the Wire library, but the use with split data lines may be a challenge.
It can be solved the hard way, designing a bitbang program, but I thought someone may have an idea how this can be achieved using a ready to use library (Modify the Wire?).
Any idea?
Thanks
9
LEDs and Multiplexing / Re: 4051 Multiplexer RFID Ante...
Last post by Tocs - Today at 03:36 pm
Hi Paul,

Here is an updated schematic.



Im trying to have it cycle through the external antenna so when something is read on one I will know what antenna was active at that time so I know where the card was read.
10
Hello MorganS

Code: [Select]
#include <Encoder.h>
#define GAIN 1
//how agressively it tries to get to the desired position
#define PWMPIN 3 // Output pin to control PWM for motor controller on digital
#define DIRPIN 2 // Output direction for motor controller on digital
#define CHANNELA 0 // motor position sensor pin Digital Pin
#define CHANNELB 1 // motor position sensor pin Digital Pin
#define POTPIN A0    // select the input pin for the potentiometer on analog pin
Encoder MyEnc(CHANNELA, CHANNELB);

void driveMotor(int speed) {
  //drive motor at desired speed
  //-255 is max reverse, +255 is max forwards
  if (speed >= 0) {
    digitalWrite(DIRPIN, 0);
    analogWrite(PWMPIN, speed);
  } else {
    digitalWrite(DIRPIN, 1);
    analogWrite(PWMPIN, -speed);
  }
}

int desiredPosition() {
  //Put the mathematics to convert pot position to encoder position here
  //This can be called from anywhere in the code with consistent results 17879
  return map(analogRead(POTPIN), 0, 1023, 0, 47000);
}

void setup() {
  pinMode(PWMPIN, OUTPUT);
  pinMode(DIRPIN, OUTPUT);
  pinMode(CHANNELA, INPUT_PULLUP);
  pinMode(CHANNELB, INPUT_PULLUP);
 
  driveMotor(0);  //stop
  delay(5000);     //delay before starting setup.
 
  //drive motor all the way one way, then take this as the zero position
  driveMotor(-50); //drive backwards slowly
  delay(8000);    //maybe it takes 8 seconds to get there?
  driveMotor(0);  //stop
  delay(100);     //let it settle.
  MyEnc.write(0); //call this zero
  //now drive the motor somewhere close to where the pot currently is
  //this is to stop it slamming there at full speed.
  while (MyEnc.read() < desiredPosition()) {
    driveMotor(0);
  }
  driveMotor(0);

  Serial.begin (9600);
}

void loop() {
  int actualPosition = MyEnc.read();
  driveMotor(GAIN * (actualPosition - desiredPosition()));

  Serial.print (actualPosition); // Print Encoder Library return
  Serial.print ("/");
}




I have cleaned up the code as you suggested and added a delay at the beginning of the loop to give me time to check all is OK.

Below is a video that shows the code above in action on the camera:
https://eshare.yr.com/fl/LoqXCD6FDF/170424_
As for Tom George comments on the pins:
I have changed the pins to:
Code: [Select]
#include <Encoder.h>
#define GAIN 1
//how agressively it tries to get to the desired position
#define PWMPIN 10 // Output pin to control PWM for motor controller on digital
#define DIRPIN 9 // Output direction for motor controller on digital
#define CHANNELA 2 // motor position sensor pin Digital Pin
#define CHANNELB 3 // motor position sensor pin Digital Pin
#define POTPIN A0    // select the input pin for the potentiometer on analog pin
Encoder MyEnc(CHANNELA, CHANNELB);


Using the pin usage as defined on the link below:
https://www.arduino.cc/en/Hacking/PinMapping32u4

I have tried all the combinations of pins where the PWM is flagged and moved the Channel A/B to interrupt enabled pins 2&3. The best combination I have found is above ... But the system is still really noisy.

In the setup part of the sketch, motor is really noisy without the quadrature read started.

Yesterday, I tried to adapt the sketch right at the top of this thread that was designed for an analog DC motor. Even if the control did not function properly at all, the motor was virtually silent as every speed.
I suspect something to do with the PWM.
Pages: [1] 2 3 ... 10

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy