Show Posts
Pages: 1 2 [3] 4 5 6
31  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
32  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
33  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?
34  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?

35  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
36  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
37  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);
  }
}


38  Using Arduino / Programming Questions / Re: counter don't count on: September 18, 2012, 07:17:06 am
Thanks for answers.
That was what I need: a changing-mind-hint...(I believe it isn't good english. smiley-red)

The sensor (line-tracer-sensor DFRobot)gives a stable analog value at 0 and 1006. So I used it on an analog port.
But now I put it in an digital-port and Arduino recognized it as HIGH and LOW.

It works fine now.

Thanks...

Johan
39  Using Arduino / Programming Questions / Re: counter don't count on: September 18, 2012, 06:16:19 am
Yes, I've thought of this thing too.
I think: the variable signal can be HIGH or LOW. So I named it a boolean. But I understand boolean is a function who give feedback a 0 or 1.

But when I changed to

int signal = 0;

counting even don't working...

Or is the problem that digitalRead only can read out a pin? And not a variable?

How can I readout the HIGH- or LOW state of an variable?

Johan
40  Using Arduino / Programming Questions / counter don't count on: September 18, 2012, 05:29:24 am
Hi,
I try to count a HIGH / LOW state of a signal.
The parts of the code (analog signal to digital signal) works.
Count-part in another sketch (standard arduinosketch ButtonStateChange) works
But in the total sketch the count-part don't work.

Anyone an idea? (of course... i'm still a very newbee...)
Below the code

Gr.
Johan

Code:
boolean signal;
int sensorvalue;
int signalCounter = 0;   // counter for the number of button presses
int signalState = 0;         // current state of the button
int lastsignalState = 0;     // previous state of the button

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

void loop(){

  sensorvalue = analogRead(A0);
  signalState = digitalRead(signal);

  if (sensorvalue == 1006){
    signal = HIGH;
  }

  if (sensorvalue == 0){
    signal = LOW;
  }
  if (signalState != lastsignalState) {
    if (signalState == HIGH) {
      signalCounter ++;
    }



    lastsignalState = signalState; 
  }
  Serial.print(sensorvalue);
  Serial.print(",");
  Serial.print(signal);
  Serial.print(",");
  Serial.println(signalCounter);
  delay(500);
}


41  Using Arduino / Programming Questions / Re: Random on: June 13, 2012, 03:59:31 am
Thanks all.
It's working for the purpose we want.
And yes, it's a strange design, but we have no time to make it better.
(pupils always start to late with their projects...)

Gr.
Johan
42  Using Arduino / Programming Questions / Random on: June 13, 2012, 02:52:41 am
Hi,

I try to turn on max 5 leds by pressing 2 buttons.
For this I used this script below.
But, after reset, the most time the same led is beaming.

Is there any improvement on it?

Gr.
Johan

Code:
int led[] = {3,4,5,6,7,8};
int numberLeds = 6;
int button1 = 9;
int button2 = 10;
 
void setup() {               
  for (i=0;i<5;i++){
    pinMode(led[i],OUTPUT);
    digitalWrite(led[i],LOW);
  }
  pinMode(button1,INPUT);
  pinMode(button2,INPUT);
}
 
void loop() {
  randomSeed(analogRead(0));
  if (digitalRead(button1)&&digitalRead(button2)){
    if(random(100)>50){
      digitalWrite(led[random(numberLeds)],HIGH);
    }
    if(random(100)>50){
      digitalWrite(led[random(numberLeds)],HIGH);
    }
    if(random(100)>50){
      digitalWrite(led[random(numberLeds)],HIGH);
    }
    if(random(100)>50){
      digitalWrite(led[random(numberLeds)],HIGH);
    }
    if(random(100)>50){
      digitalWrite(led[random(numberLeds)],HIGH);
    }
    while(true){
      delay(1000);
    }
  }
}
43  International / Nederlands / Re: arduino en robotics onderdelen - favo shops in BE en NL ? on: April 19, 2012, 05:32:05 am
Ik mis Farnell nog in dit rijtje. Enorme keus aan elektronica componenten. Zelfs ook wat arduino spulletjes.
Voor scholen en bedrijven werkt deze firma zonder verzendkosten.
Dus of het nou een onderdeeltje is van 10 eurocent of 100 euro, de volgende dag heb je 't binnen.

Goede site ook met veel filter mogelijkheden (moet ook wel...).

Aanbevolen.

http://nl.farnell.com

Groet,
Johan Nijsse
44  Using Arduino / Installation & Troubleshooting / Re: POP-BOT Inex upload trouble on: March 20, 2012, 10:03:57 am
Works!
Fine, thank you.

Gr.
Johan
45  Using Arduino / Installation & Troubleshooting / POP-BOT Inex upload trouble on: March 20, 2012, 03:42:47 am
Hi,

We're using a INEX POP-BOT (with Arduino POP-168 -> Board have to set on Arduino Mini).
And suddenly, after fine using, it don't upload. Arduino gives the mean error: avrdude: stk500_getsync(): not in sync: resp=0x00 etc.

What happened?

The usb cable works fine, device manager gives no trouble, the POP-BOT itselfs works fine with the program that was upload at last. But it don't upload again.

Is there any manner to give a deep reset? Or have the pupils (we use them at school) faked the bootloader?

Anyone experience with this robot?

Gr.
Johan

Pages: 1 2 [3] 4 5 6