Pages: [1] 2   Go Down
Author Topic: Need help making a custom barcode reader  (Read 1441 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
i am making a custom code scanner using 2 rows of black and white the bottom row is black white black white etc it is 8 bit so 4 white 4 black. to indicate the upper row so if the bottom rows sees the upper row is changing, it converts the input into binary like: black white white white white white white white will be 1. i use 2 line tracking sensors for this im also using a servo motor to make the codes circle so the scanner can read them. what im trying to put in rigth now is that if the maxnum wich is 8 including 0 == a random number between 0-7  it stops the motor waits 3 seconds and returns to his routine. i have already added that it stops at a random number between 1-3. but i want to make it more accurate so it stops between 0-7 of the bottom row here is my code:
Code:
#include <Wire.h>                     //used for the lcd
#include <LiquidCrystal_I2C.h>
#include <Time.h>  
#define TIME_MSG_LEN  11
#define TIME_HEADER  'T'
#define TIME_REQUEST  7  
int oldval=1;                          //used to indicate if the upper row changed
int count=0;                           //changes everytime the bottom row changes and increases once it reached maxnum wich is 8 it resets itself
int val = 1;                           //used to calculate from binary to decimal
int maxnum=8;                          //the max number of counts that the scanner does before it resets itself
int pos = 0;                           //used to calculate from binary to decimal
int scans = 0;                         //the variable that changes everytime it scanned one code it shows the amount of scans he did
int E2 = 9;                            //for the servo motor
int M2 = 10;                           //for the servo motor
//int change = 0;                      
long randNumber;                       //the random number for the upper row the binary code converted to decimal with a max of 3 and a min of 1
long randCount;                        //the random number for the bottom row from 0-7
//int displayval = 0;                  

LiquidCrystal_I2C lcd(0x27,20,4);      //for the lcd to work


void setup()
{
  Serial.begin(9600);
  int ledPin = 8;                      // changing pin 8 to 5v
  pinMode(ledPin, OUTPUT);  
  digitalWrite(ledPin, HIGH);
  int ledPin2 = 7;                     // changing pin 7 to 5v
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin2, HIGH);
  int ledPin3 = 4;                     // changing pin 4 to 5v
  pinMode(ledPin3, OUTPUT);
  digitalWrite(ledPin3, HIGH);        
  attachInterrupt(0, Poort, CHANGE);   //the attachinterrupt to see if the bottom row changes so it knows to look at the upper row
  lcd.init();                          //to keep the lcd on
  lcd.backlight();                     //to keep the backlight of the lcd on
  randNumber = random(1, 4);           //generates a random number for the randNumb to stop (this works)

  analogWrite (E2,75);                 //to keep the servo motor running to circle the codes
  digitalWrite(M2,HIGH);

  lcd.setCursor(15,3);                 //is for the display don't need to look at this
  lcd.print(randNumber);          
  lcd.setCursor(13,2);
  lcd.print("Dest:");
  lcd.setCursor(0,0);
  lcd.print("Aantal Gescanned:");
  lcd.setCursor(0,1);
  lcd.print(scans);
  lcd.setCursor(0,2);
  lcd.print("Waarde: ");
}

void loop(){    

  if (count == 7)                      //if the count reaches 7 it updates the lcd
  {
    lcd.setCursor(0,3);  
    lcd.print(pos);
    lcd.print(" ");
    lcd.setCursor(0,1);
  }
  if (pos == randNumber)              // if the decimal number wich is converted from decimal in the interrupt == the random number generated in the setup it slows down the servo to be more accurate at his stop
  {
    analogWrite (E2,110);
    lcd.setCursor(15,3);              //for the lcd
    lcd.print(randNumber);
    lcd.print(scans++);               //adds a scan everytime it passes this
    randNumber = random(1, 4)
    if (randCount == count)          //if the random nummer generated for the bottom row == to the the count wich counts every square in the bottom row it stops the servo generates a new randomnumber waits 3 seconds generates a new random number for the count
    {
      analogWrite (E2, 200);  
      randNumber = random(1, 4);
      delay(3000);
      randCount = random(0, 7);
      analogWrite (E2, 75);          //after the 3 seconds it goes back to normal speed
    }
  }
}

void Poort(){                        //the interrupt where i build in a debug system to see what it does and if it does what i want
  Serial.print(count);
  Serial.print(" - ");
  Serial.print(digitalRead(2));
  Serial.print(" - ");
  Serial.print(digitalRead(3));
  Serial.print(" - ");  
  Serial.print(randCount);
  Serial.print(" - ");
  Serial.print(randNumber);
  Serial.print(" - ");

  count++;                                     //everytime it changes it adds one count for the blocks
  pos = pos + (val * (1-digitalRead(3)));      //calculates binary to decimal pin 3 is the sensor for the upper row
  val = val * 2;                               //calculates binary to decimal

  Serial.print(pos);                           //after it calculated it it outputs the decimal into to monitor for me to check it
  Serial.println(" ");


  if (count == maxnum)                         //once the count changed 8 times it resets the variables to startover
  {
    count = 0;
    pos = 0;
    val = 1;

  }
}

i have no clue how to fix it. right now when i run it it sometimes work. i think it may have to do with the loop and the interrupt but i don't know how to fix this.
the lcd.print is just to make it easier to read when im next to the arduino.

right now it doesnt slow down and it stops at one point in the code only. i dont think he uses the randCount

this is the what i see in my monitor.
first row: the count counts to 8 everytime in order to get a 8 bit binary code (works)
second row: the bottom row to indicate if the upper has to change aswell (works)
third row: the upper row shows a 0 for black square and 1 for a white square (works)
fourth row: shows the randCount a random nummer generated used to make it stop at a place in the count (does not work)
fifth row: shows the randNumb a number generated to stop at a certain code after the code is calculated wich is after 8 squares (works)
sixth row: shows the number calculated from the binary code (works)



Code:
0 - 0 - 0 - 0 - 2 - 1
1 - 1 - 1 - 0 - 2 - 1
2 - 0 - 1 - 0 - 2 - 1
3 - 1 - 1 - 0 - 2 - 1
4 - 0 - 1 - 0 - 2 - 1
5 - 1 - 1 - 0 - 2 - 1
6 - 0 - 1 - 0 - 2 - 1
7 - 1 - 1 - 0 - 2 - 1
0 - 0 - 0 - 0 - 2 - 1
1 - 1 - 0 - 0 - 2 - 3
2 - 0 - 1 - 0 - 2 - 3
3 - 1 - 1 - 0 - 2 - 3
4 - 0 - 1 - 0 - 2 - 3
5 - 1 - 1 - 0 - 2 - 3
6 - 0 - 1 - 0 - 2 - 3
7 - 1 - 1 - 0 - 2 - 3
0 - 0 - 0 - 0 - 2 - 1
1 - 1 - 1 - 0 - 2 - 1
2 - 0 - 1 - 0 - 2 - 1
3 - 1 - 1 - 0 - 2 - 1
4 - 0 - 1 - 0 - 2 - 1
5 - 1 - 1 - 0 - 2 - 1
6 - 0 - 1 - 0 - 2 - 1
7 - 1 - 1 - 0 - 2 - 1
0 - 0 - 1 - 0 - 2 - 0
1 - 1 - 0 - 0 - 2 - 2
2 - 0 - 1 - 2 - 3 - 2
3 - 1 - 1 - 6 - 3 - 2
4 - 0 - 1 - 6 - 3 - 2
5 - 1 - 1 - 6 - 3 - 2
6 - 0 - 1 - 6 - 3 - 2
7 - 1 - 1 - 6 - 3 - 2
« Last Edit: November 13, 2012, 06:57:43 am by Chocolatee » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Take a deep breath, and try again. Use some paragraphs to separate your thoughts. I can't even begin to tell what your problem is.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what do you need incase to help me i can give you the information im only 16 years old and english isn't my native language so i will try to provide you with the information you need but i have only worked with an arduino for about 3 weeks now
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what do you need incase to help me i can give you the information im only 16 years old and english isn't my native language so i will try to provide you with the information you need but i have only worked with an arduino for about 3 weeks now
Whether or not English is your native language, you surely recognize that punctuation is required at the end of sentences. They define where one thought ends and another begins.  Try again.

Explain what your problem is. What does the code do? What do you want it to do? How are those different?

Some paragraphs are good, too.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

allright i don't know what to add more to this. this is all the information i got.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26293
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is all the information i got.
Maybe think about how you should present it to people who don't have that information.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whether or not English is your native language, you surely recognize that punctuation is required at the end of sentences. They define where one thought ends and another begins.  Try again.

Explain what your problem is. What does the code do? What do you want it to do? How are those different?

Some paragraphs are good, too.

can you please try again now that i have given all the information i have.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it bassicly needs to scan those codes convert it into decimal. so he can recognize where he is by reading those codes if he is at a random code generated in the my code he has to stop (wich works)
but now i want to make it stop in the middle of a code.

like:
his destination is 4. he knows that after scanning all the 8 squares than he has to slow down and stop somewhere in the middle of the next code. at wich square of the eight is also completely random.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26293
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you saying you have a clock track and a data track?

Your sentence structure is really hard to follow.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im sorry.
the upper one is the binary code
and the bottom one is just to indicate if the sensor has to read the upper one

like:
black.white.white.white.white.white.white.white
white.black.white.black.white.black.white.black

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26293
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, yes, a clock track.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, if you need more information or if you don't understand anything. ask me.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i really have no idea's left, if anyone has suggestions it doesn't matter if it doesn't work. Or some other things i should try?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if you don't understand anything. ask me.
I already did. That code does something. What?

You want it to do something. What?

How are those two different?

Is your shift key broken?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dude you do understand my sentences without capitals, like i said.
Quote
it bassicly needs to scan those codes convert it into decimal. so he can recognize where he is by reading those codes if he is at a random code generated in the my code he has to stop (wich works)
but now i want to make it stop in the middle of a code.

like:
his destination is 4. he knows that after scanning all the 8 squares than he has to slow down and stop somewhere in the middle of the next code. at wich square of the eight is also completely random.
i also explained almost every single piece of code. Above.
« Last Edit: November 13, 2012, 08:29:38 am by Chocolatee » Logged

Pages: [1] 2   Go Up
Jump to: