Show Posts
Pages: 1 [2] 3 4 5
16  Using Arduino / Programming Questions / Re: keypad read out on: April 25, 2013, 02:13:36 am
With these comments I can get to work! Thanks all for thinging with me.

@billroy
It didn't.
code must be filled with the entered code from the keypad.
And at last all four digits must be in 'code'. So code == 1234.
Therefor code was first 1, after next input 2, then 3, then 4. But not the whole securecode.

Gr.
Johan
17  Using Arduino / Programming Questions / Re: keypad read out on: April 24, 2013, 04:03:01 am
Fine, it works.

But i'm interested in solution with use of an array.
How can I fill 4 positions of an array with 4 different getKeys()?

Gr.
Johan
18  International / Nederlands / Re: keypad code uitlezen on: April 24, 2013, 03:16:00 am
Opgelost:
int code stond op een of andere manier binnen de loop en moest globaal gedefinieerd worden.

Bedankt voor het meedenken...

Gr.
Johan
19  Using Arduino / Programming Questions / keypad read out on: April 24, 2013, 02:39:54 am
Hi,

I want to use a keypad for a security lock.
When I put in the right code (p.e. 1234), the locker is open, or a green led flashes or something.

I used the code from the keypad library with some changes in the loop. Such as:

Code:
#include <Keypad.h>
 
const byte ROWS = 4; //four rows
 const byte COLS = 3; //three columns
 char keys[ROWS][COLS] = {
   {'1','2','3'},
   {'4','5','6'},
   {'7','8','9'},
   {'#','0','*'}
 };
 byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
 byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 
void setup(){
   Serial.begin(9600);
 }
 
void loop(){
int code;
int secureCode = 1234;

   char key = keypad.getKey();
 
  if (key != NO_KEY){
    code = code * 10 + key - '0';
     Serial.println(code);
   }
 }
...and other code to check the secureCode...

The problem is that everytime when I put a new number, this number comes on a new line.
So the int code won't be filled with 1234, but first 1, then 2. A new input replaces the old value.
How can i solve this?

I was thinking of an array, to put in the codes. When array is complete, check his content en give action or not. But experts from the dutch forum not recommended this.

Gr.
Johan
20  International / Nederlands / Re: keypad code uitlezen on: April 24, 2013, 02:22:14 am
Hmmm, nog steeds zelfde probleem.
Code uit het O'Reilly Cookbook gebruikt, zonder library.
Ik ga, zonder jouw expertise te onderschatten (de meesten hier zijn vele malen verder dan mij!), de vraag ook even op het algemene forum neerleggen.
Mogelijk krijg ik dan nieuwe inzichten.

Gr.
Johan
21  International / Nederlands / Re: keypad code uitlezen on: April 24, 2013, 01:48:01 am
Ik gebruik de library Keypad.
Om het keypad uit te lezen stond in het voorbeeldbestand de functie getKey()

Zou het mogelijk zijn dat in de functie getKey() standaard een newline commando zit?

Ik zal eens een poging doen met een sketch zonder gebruik van deze library.

Gr.
Johan
22  International / Nederlands / Re: keypad code uitlezen on: April 23, 2013, 06:24:46 am
Beste Jantje,
Even je code geprobeerd, maar dat werkt nog niet.

Code:
int geheimeCode = 1234;
int code = 0;
void loop(){
  char customKey = customKeypad.getKey();
 
  if (customKey){
    code=code*10+customKey-'0';
    Serial.println(code);
  }
}

Ik was dus even bij het begin begonnen en had puur de code geprint. Nog zonder acties van als if code == geheimeCode etc.
Als ik nu 1 druk, komt er 1.
Druk ik daarna 2, komt er alleen 2. En niet 12. Hij vervangt die 1 gewoon door die 2. Lijkt me...

Maar hij moet 4 getallen in één 'ding' zetten en die getallen samen controleren.
Vandaar eigenlijk mijn gedachte met die array. Daarin kun je 4 getallen plaatsen en daarna (dacht ik dus) die 4 getallen als één getal uitlezen.

Whats wrong?

Gr.
Johan
23  International / Nederlands / Re: keypad code uitlezen on: April 23, 2013, 02:03:04 am
Naar zo'n soort truc was ik idd op zoek.
Mijn gedachte was dat de 'int code' steeds weer opnieuw gevuld wordt, dus nooit de totaal ingetoetste code kan bevatten.
Maar door het *10 en minus het nulletje te doen, zou dat moeten kunnen. We gaan het proberen.

Nog even terugkomend op die array gedachte: Je kunt een array toch vullen met 'customKey'? Hoe werkt dat dan?
Ik snap wel hoe je bepaalde waarde uit een array haalt, maar hoe zet je een getal/letter op een bepaalde positie in de array?

Bedankt alvast voor de hulp.

Gr.
Johan
24  International / Nederlands / keypad code uitlezen on: April 22, 2013, 08:40:57 am
Hoi,

Ik wil met een keypad een beveiligingscode intoetsen, deze controleren en vervolgens goed- of foutkeuren.
Met de Custom-keypad uit de  keypad-library zit ik in elk geval al handig op weg om de cijfers weer te geven.

Het lijkt me dat ik een array moet vullen met bijv. 4 cijfers.
Zijn deze cijfers goed (hoe controleer ik dat?) volgt er een actie.

Maar ik snap het principe niet zo van een array en hoe daar mee om te gaan.

Of zou het handiger op een andere manier kunnen?

Hier de code uit de library:
Code:
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
  Serial.begin(9600);
}
 
void loop(){
  char customKey = customKeypad.getKey();
 
  if (customKey){
    Serial.println(customKey);
  }
}

Is het volgende (afgezien van de syntax) een idee?

Code:
if (customKey){
//zet deze key ergens (in een array?) en wacht op de volgende
}
if (array = in orde){
//maak de deur open o.i.d.
}

Groet,
Johan
25  Using Arduino / Programming Questions / Re: virtual wire multiple values on: February 01, 2013, 04:36:57 am
With tips & trucks from all of you at least i have a code which is working (completed with a DHT11 sensor):

Sender:
Code:
#include <VirtualWire.h>
#include <DHT.h>

#define DHTPIN 2

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  Serial.begin(9600);
  Serial.println("setup");
  vw_set_tx_pin(12);
  vw_setup(2000);
  pinMode(13,OUTPUT);
  dht.begin();
}
void loop()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();

  String messageString = String();
  for(int i=0;i<6;i++){
    messageString.concat(analogRead(i));
    messageString.concat(",");
  }
  messageString.concat(t);
  messageString.concat(",");
  messageString.concat(h);
  messageString.concat(",");

  char msg[messageString.length()+1];
  messageString.toCharArray(msg,messageString.length()+1);
  digitalWrite(13, true);
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx();
  digitalWrite(13, false);
  delay(1000);
}

Reciever:

Code:
#include <VirtualWire.h>
void setup()
{
     Serial.begin(9600);
    Serial.println("setup");
    Serial.println("CLEARDATA");
    vw_setup(2000);
    vw_set_rx_pin(11);
    vw_rx_start();
    pinMode(13,OUTPUT);
}
void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen))
    {
int i;
digitalWrite(13, true);
//Serial.print("Got:   ");
Serial.println("CLEARDATA");
Serial.print("DATA, ,");
for (i = 0; i < buflen; i++)
{
 
    Serial.write(buf[i]);
    Serial.print(" ");
}
Serial.println(" ");

     digitalWrite(13, false);
    }
}

The concat-function works fine for me.
The CLEARDATA and DATA prints are necessary for the transport to Excel.

Thanks so far...

Gr.
Johan
26  Using Arduino / Programming Questions / Re: virtual wire multiple values on: January 30, 2013, 08:49:29 am
Ok, i'll try:

Sender code:
Code:

#include <VirtualWire.h>

// LED's
const int ledPin = 13;

// Sensors
const int licht = A0;
const int co2 = A5;

int lichtData;
int co2Data;
char lichtCharMsg[5];
char co2CharMsg[5];

void setup() {

  // PinModes
  // LED
  pinMode(ledPin,OUTPUT);

  // for debugging
  Serial.begin(9600);

  // VirtualWire setup
  vw_setup(2000);     // Bits per sec


}

void loop() {

  // Read and store Sensor data
  lichtData = analogRead(licht);
  co2Data = analogRead(co2);

  // Convert integer data to Char array directly
  itoa(lichtData,lichtCharMsg,10);
  itoa(co2Data,co2CharMsg,10);

  // DEBUG
  //  Serial.print("licht Integer: ");
  //  Serial.print(lichtData);
  //  Serial.print(" licht CharMsg: ");
  Serial.print(lichtCharMsg);
  //  Serial.print("co2 Integer: ");
  //  Serial.print(co2Data);
  Serial.print("\t");
  //  Serial.print(" co2 CharMsg: ");
  Serial.println(co2CharMsg);
  //  Serial.println(" ");
  delay(1000);

  // END DEBUG

  digitalWrite(13, true); // Turn on a light to show transmitting
  vw_send((uint8_t *)lichtCharMsg, strlen(lichtCharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
  vw_send((uint8_t *)co2CharMsg, strlen(co2CharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, false); // Turn off a light after transmission
  delay(200);

} // END void loop...


With output:

01023
01023
01023
etc... every second

Reciever's code:

Code:

#include <VirtualWire.h>

// LED's
int ledPin = 13;

// Sensors
int lichtData;
int co2Data;

// RF Transmission container
char lichtCharMsg[5];
char co2CharMsg[5];

void setup() {
  Serial.begin(9600);

  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);     

  // VirtualWire
  // Initialise the IO and ISR
  // Required for DR3100
  vw_set_ptt_inverted(true);
  // Bits per sec
  vw_setup(2000);     

  // Start the receiver PLL running
  vw_rx_start();       

} // END void setup

void loop(){
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  // Non-blocking
  if (vw_get_message(buf, &buflen))
  {
    int i;
    // Turn on a light to show received good message
    digitalWrite(13, true);

    // Message with a good checksum received, dump it.
    for (i = 0; i < buflen; i++)
    {           
      // Fill Sensor1CharMsg Char array with corresponding
      // chars from buffer.   
      lichtCharMsg[i] = char(buf[i]);


    }

    int j;
    for (j = 0; j < buflen; j++)
    {
      co2CharMsg[j] = char(buf[j]);
    }

    // Null terminate the char array
    // This needs to be done otherwise problems will occur
    // when the incoming messages has less digits than the
    // one before.
    lichtCharMsg[buflen] = '\0';
    co2CharMsg[buflen] = '\0';

    // Convert Sensor1CharMsg Char array to integer
    lichtData = atoi(lichtCharMsg);
    co2Data = atoi(co2CharMsg);


    // DEBUG
    //    Serial.print("Licht: ");
    Serial.print(lichtCharMsg);
    Serial.print("\t");
    //    Serial.print("CO2: ");
    Serial.println(co2CharMsg);

    // END DEBUG

    // Turn off light to and await next message
    digitalWrite(13, false);
  }
}

With output:

0      0
1023  1023
0      0
1023  1023
0      0
1023  1023
etc. every second two lines.

Is this what you want to see? Or is there another way to post the real output? A printscreen from the serialmonitor?
27  Using Arduino / Programming Questions / Re: virtual wire multiple values on: January 30, 2013, 08:14:40 am
Ah, so.
But the code isn't changed from the one in my starterpost, only your suggestion to make an array from 5 instead of 4, and i've changed the serial.print commands a little bit:

Transmitter:
Code:
  Serial.print(lichtCharMsg);
  Serial.print("\t);
  Serial.println(co2CharMsg);
  delay(1000);

Gives in the serial monitor: 0   1023 (i've put them in GND and 5V)

Reciever:
Code:
    Serial.print(lichtCharMsg);
    Serial.print("\t");
    Serial.println(co2CharMsg);

Gives in the serial monitor
0       0
1023  1023

Twice the lightvalue and twice the co2value.

Could it be a delay problem? That the transmitter sends faster than the reciever could handle?

28  Using Arduino / Programming Questions / Re: virtual wire multiple values on: January 30, 2013, 02:54:51 am
Beats you? Sorry, Seattle is to  far  from Holland.
Means 'Beats me' the same as 'I don't know' or means it like 'stupid! Don't you see this?'
Indeed i'm still a newbie. But i don't work the whole day with arduino.
 
Why comes in one loop two lines of serial data at the recievers side?
Anyone another less painfull answer?

Johan
29  Using Arduino / Programming Questions / Re: virtual wire multiple values on: January 29, 2013, 09:24:21 am
Thanks. It's better.
But now the Serial Monitor from the reciever shows:

985       985
1023     1023

Every loop it gives two lines.
The first row is twice the lightsensor.
The second row is twice a 5V signal.

I want to see:

985     1023

What's wrong  with the Serial.print commands in the code?

Gr.
Johan
30  Using Arduino / Programming Questions / virtual wire multiple values on: January 29, 2013, 06:53:37 am
Hi,

I used a sketch from the internet to send by RFLink one sensor value to another arduino board. It works well.
But my purpose is to send multiple values, such as light, temperature, CO2-concentration, humidity etc.
So I try to change the sketch for two sensorvalues, but now there are (for me) not-understandable things.

At the recievers side comes the serial data as follow:

983     983
1023    0

2 lines every time.
983 and 1023 (first numbers in the row) are good values.
The other 2 values (983 and 0) are not known. 983 looks like a mirror of the first value.
But were in the code is it going wrong.
Refers it to the char [4]?

Also I don't understand the code at the end of the reciever about buflen.
The int i was in the original sketch.
The int j was invented by myself, because i thought there are two sensors so there must be two charMsg's.

Correct me, please, if I'm wrong.

Gr.
Johan
 
Here's the code from the transmitter (some words are in dutch...):
Code:

#include <VirtualWire.h>

// LED's
const int ledPin = 13;

// Sensors
const int licht = A0;
const int co2 = A1;

int lichtData;
int co2Data;
char lichtCharMsg[4];
char co2CharMsg[4];

void setup() {

  // PinModes
  // LED
  pinMode(ledPin,OUTPUT);

  // for debugging
  Serial.begin(9600);

  // VirtualWire setup
  vw_setup(2000);     // Bits per sec


}

void loop() {

  // Read and store Sensor data
  lichtData = analogRead(licht);
  co2Data = analogRead(co2);

  // Convert integer data to Char array directly
  itoa(lichtData,lichtCharMsg,10);
  itoa(co2Data,co2CharMsg,10);

  // DEBUG
  Serial.print("licht Integer: ");
  Serial.print(lichtData);
  Serial.print(" licht CharMsg: ");
  Serial.print(lichtCharMsg);
  Serial.print("co2 Integer: ");
  Serial.print(co2Data);

  Serial.print(" co2 CharMsg: ");
  Serial.print(co2CharMsg);
  Serial.println(" ");
  delay(1000);

  // END DEBUG

  digitalWrite(13, true); // Turn on a light to show transmitting
  vw_send((uint8_t *)lichtCharMsg, strlen(lichtCharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
  vw_send((uint8_t *)co2CharMsg, strlen(co2CharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, false); // Turn off a light after transmission
  delay(200);

} // END void loop...

And this is the code from the reciever.

Code:
#include <VirtualWire.h>

// LED's
int ledPin = 13;

// Sensors
int lichtData;
int co2Data;

// RF Transmission container
char lichtCharMsg[4];
char co2CharMsg[4];

void setup() {
  Serial.begin(9600);

  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);     

  // VirtualWire
  // Initialise the IO and ISR
  // Required for DR3100
  vw_set_ptt_inverted(true);
  // Bits per sec
  vw_setup(2000);     

  // Start the receiver PLL running
  vw_rx_start();       

} // END void setup

void loop(){
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  // Non-blocking
  if (vw_get_message(buf, &buflen))
  {
    int i;
    // Turn on a light to show received good message
    digitalWrite(13, true);

    // Message with a good checksum received, dump it.
    for (i = 0; i < buflen; i++)
    {           
      // Fill Sensor1CharMsg Char array with corresponding
      // chars from buffer.   
      lichtCharMsg[i] = char(buf[i]);


    }

    int j;
    for (j = 0; j < buflen; j++)
    {
      co2CharMsg[j] = char(buf[j]);
    }

    // Null terminate the char array
    // This needs to be done otherwise problems will occur
    // when the incoming messages has less digits than the
    // one before.
    lichtCharMsg[buflen] = '\0';
    co2CharMsg[buflen] = '\0';

    // Convert Sensor1CharMsg Char array to integer
    lichtData = atoi(lichtCharMsg);
    co2Data = atoi(co2CharMsg);


    // DEBUG
    Serial.print("Licht: ");
    Serial.print(lichtData);
    Serial.print("\t");
    Serial.print("CO2: ");
    Serial.println(co2Data);

    // END DEBUG

    // Turn off light to and await next message
    digitalWrite(13, false);
  }
}


Pages: 1 [2] 3 4 5