Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Code keeps locking up and refuses to respond on: February 16, 2014, 02:46:16 am
Oh wow! Thank you so much
2  Using Arduino / Programming Questions / Code keeps locking up and refuses to respond on: February 16, 2014, 02:15:54 am
Hello, I wrote a small sketch that interacts with a 74hc165 shift register. It basically reads the shift register stores the output in an array and then displays the contents to the serial monitor.
However, the serial monitor never displays anything.
I tried turning the led on pin 13 on at the start of the void loop and turning it off before the delay, essentially making it blink as the program would run. But the led wouldn't blink. This leads me to believe the program is locking up somewhere in the middle, and I nor my colleagues can seem to figure out why.

I used both an Arduino Leonardo and Arduino Uno, and received similar results from both. You don' t need a shift register for this sketch. Feel free to upload the code to a bare arduino and try to see if you can get at least dummy data to output on the display.

Code:
byte piso_load = 4; //piso shift register parallel load pin, active low
byte piso_clock = 7; //piso shift register clock pin, low to high transition
byte piso_out = 8; //piso shift register data output
byte piso_clockenable = 9; //piso shift register clock enable pin, low when shifting out

int bits[8] = {0,0,0,0,0,0,0,0};

void setup(){
  Serial.begin(9600);
  while(!Serial);
  pinMode(piso_load, OUTPUT);
  pinMode(piso_clock, OUTPUT);
  pinMode(piso_out, INPUT);
  pinMode(piso_clockenable, OUTPUT);
  
  //set to high
  digitalWrite(piso_load, HIGH);
  digitalWrite(piso_clockenable, HIGH);
}

void loop(){
  
  //load in data
  digitalWrite(piso_load, LOW);
  digitalWrite(piso_load, HIGH);
  
  //allow data to be shifted out
  digitalWrite(piso_clockenable, LOW);
  
  for(byte ctr=7; ctr>=0; ctr--){
    //send a clock pulse to shift out current bit
    digitalWrite(piso_clock, LOW);
    digitalWrite(piso_clock, HIGH);  
    
    bits[ctr] = digitalRead(piso_out);
  }
  
  //disable clock pin
  digitalWrite(piso_clockenable, HIGH);
  
  for(byte ctr=0; ctr<8; ctr++){
    Serial.print(bits[ctr]);
  }
  
  delay(100);
  
}

Thanks, any help would be appreciated!
3  Topics / Device Hacking / Re: Sparkfun Color LCD + Arduino ? on: November 30, 2013, 02:21:09 am
You have to power the LCD with 3.3V. Therefore you might need to connect to your 5V Arduino to the 3.3V LCD with a logic level converter.
4  Using Arduino / General Electronics / Re: MOSFET saturation question on: May 19, 2013, 01:40:06 pm
The gate-source voltage is 20V not 2.5V. Also how much current are you planning to go from drain to source?
5  Using Arduino / Project Guidance / Problem with converting this single line in a library example to Arduino 1.0 on: May 19, 2013, 01:35:18 pm
Hello, I downloaded and installed a SparkFun library for controlling this camera: https://www.sparkfun.com/products/10061
but when I verified the code I got this error report:
Code:
As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

on the line of code that looks like this(line 73):
Code:
MemoryCard.file.print(response[i], BYTE);

So I tried this:
Code:
MemoryCard.file.write(response[i]);

but, that didn't work either as I got this error report:
Code:
error: overriding 'virtual size_t Print::write(uint8_t)'

So my question is how do I fix that line to make it Arduino 1.0 compatible?
6  Using Arduino / Programming Questions / Re: How to reset the values in a char pointer array on: May 09, 2013, 07:13:04 pm
Thank you, I will try that now. It's the only logical thing left. I really appreciate your help everyone, especially to billroy for sticking with me on this one!
7  Using Arduino / General Electronics / Re: My Arduino Nano decided to stop working? on: May 09, 2013, 07:04:49 pm
You might have broken something on the Arduino itself, you should try probing the Arduino with a multimeter to see if there's any voltage present on the actual board.
8  Using Arduino / Programming Questions / Re: How to reset the values in a char pointer array on: May 09, 2013, 07:00:18 pm
I apologize, what I mean is that it won't print out the new ID to the Serial monitor and after you give it a new money value it won't run the rest of the code to save the file, like it does the first time you run it.
9  Using Arduino / Programming Questions / Re: How to reset the values in a char pointer array on: May 09, 2013, 06:48:57 pm
Yeah I edited my previous post it explains what the code is trying to accomplish.
10  Using Arduino / Programming Questions / Re: How to reset the values in a char pointer array on: May 09, 2013, 06:41:37 pm
My code is pretty long >130 lines but the problem is the first statement in void loop() so it's pretty easy to find.
I really appreciate any help!
The code is pretty fun to use, just need an Arduino with SD card and SD card shield.
Run the code and open the Serial monitor. Then type in an 8 digit number ID (random numbers will work) and then type in an amount of money, (numbers and terminate the numbers with an 'e', like this --> 123e). It'll create the file and print some stuff. And then it'll ask for another ID again, the problem is when you run through it again it doesn't work, I need the id[] and money[] arrays to be cleared because the code doesn't work with the old values stored there.
I hope this makes sense, feel free to run this code, it's really cool!

Code:
#include <SD.h>
#include <string.h>
byte SD_CS = 4; //Chip select of SD reader
File cust_file; //to call text file
char id[50]; //name of text file
int id_index = 0;
char money[50]; //value in text file
int money_index = 0;
char money_read[50]; //value read from text file
int money_read_index = 0;
float valueFloat; //typecasted valueReceive
int input; //user input
byte id_counter = 0;
byte money_counter = 0;
float old_money, current_money, new_money; //old is stored, current is entered, new is to write
char cl = '\0';
boolean clrd = 0; //only clears memory when data has already been written

void setup(){
  Serial.begin(9600); //open serial port
  Serial.println("Initializing SD Card");
  pinMode(SD_CS, OUTPUT); //CS for SD card
  pinMode(10, OUTPUT); //CS must be an output for SPI to work
    
  if(!SD.begin(SD_CS)){ //tests to see if SD card initialization failed
  Serial.println("SD card initialization failed");
  return;
  }
  Serial.println("SD card initialization success");
    
  Serial.println("Enter in ID:"); //prompts user to enter in a value to store
  id[id_index++] = '/';  // Root directory
}

void loop(){
  while(clrd){ //part that creates the problem!
    memset(id, '\0', 50);
    memset(money, '\0', 50);
    clrd = 0;
  }      
  get_id();
  get_current();
  get_old();
  get_new();
}

void get_id(){ //gets ID(filename) from user to name file
 
  while(Serial.available()){ //read data from Serial port
    input = Serial.read();
    if(input>='0' && input<='9'){
      id[id_index++] = input;
    }
    strcpy(id+id_index, ".txt"); //converts to pointer array
    id_counter++;
  }
  
  if(id_counter>=8){ //if filename complete
    Serial.print("ID Entered is: "); //print id entered to Serial
    Serial.println(id);
    Serial.println("Enter in money:"); //prompt user to enter in money
  }
  else{
   get_id(); //otherwise go back to function
  }
}

void get_current(){ //gets current input from user
  id_counter = 0; //prevents code from repeating itself over and over.
  while(Serial.available()){ //reads data from serial port and save in pointer array
    input = Serial.read();
    if(input>='0' && input<='9'){
      money[money_index++] = input; //saves user input to money index
    }
    else if(input=='e'){
     money_counter = 1;
    }
  }
  if(money_counter==1){
    strcpy(money+money_index, ""); //converts to pointer array
    current_money = atof(money); //current_money is saved from money pointer array after being converted to float
    Serial.print("Money entered is: "); //print money entered to Serial
    Serial.println(current_money);
    Serial.println(" "); //blank line
  }
  else{
   get_current();
  }
}

void get_old(){ //gets old value from file if exists, if file doesn't exist create one first
  money_counter = 0; //prevents code from repeating itself over and over.
cust_file = SD.open(id, FILE_READ); //open file at beginning
  if(!cust_file){ //if file not already present, create one
    cust_file = SD.open(id, FILE_WRITE); //create file
    Serial.print("Created file: "); //prints new file name
    Serial.println(id);
    Serial.println(" ");
  }
  if(cust_file){ //if file is available
 while(cust_file.available()){
            for(byte c=0; c<50; c++){
     money_read[money_read_index++] = cust_file.read(); //store file contents
   }
 }
  old_money = atof(money_read); //stores the array as a float in old_money
  Serial.print("File available, old money stored is: "); //prints old money stored
  Serial.print(old_money);                //in file to Serial Serial.println(old_money); //print old_money
  Serial.println(" "); //blank line
  cust_file.close(); //close file
  }
}

void get_new(){ //get new_money by computing current_money and old_money
  new_money = current_money + old_money;
  if(new_money>=100.0){ //if new_money greater than 100 than print coupon and subtract 100
    new_money -= 100.0;
    Serial.println("You have a $5 discount!");
    Serial.print("You have $");
    Serial.print(new_money);
    Serial.println(" left.");
    Serial.println(" ");
  }
  else if(new_money<100.0){ //if new_money less than 100 print new_money
    Serial.print("You have $");
    Serial.print(new_money);
    Serial.println(" now.");
    Serial.println(" ");
  }
  cust_file = SD.open(id, FILE_WRITE);
  cust_file.print(new_money);
  cust_file.close();
  Serial.println("File written."); //shows user that file has been successfully written  
  Serial.println(" "); //prints blank line
  Serial.println("Enter ID:"); //prompts user to enter next ID
  clrd = 1; //lets the data in id and money arrays clear
  loop();
}
11  Using Arduino / Motors, Mechanics, and Power / Re: Code for stopping a 12vDc brushed motor with on: May 09, 2013, 06:27:59 pm
Yeah measure in seconds. But it's not a very precise way to get the right number of turns, so you might need to use a rotary encoder but I don't  have any experience with them. However the H-bridge shield is pretty easy and there's even example code on the site I sent you earlier.
12  Using Arduino / Motors, Mechanics, and Power / Re: What is the best way to control 4 motors? on: May 09, 2013, 06:18:32 pm
Maybe some push buttons so you can digitally talk to the Arduino. The Arduino can read the digital HIGH's and LOW's from the buttons and control the motor shield.
13  Using Arduino / Programming Questions / How to reset the values in a char pointer array on: May 09, 2013, 06:13:13 pm
Hello, in my code I need to reset a char pointer array while the Arduino is running (ex. char id[50]; ), after I fill it with data.
I can't wait to reset it or relaunch it. I've tried the various methods listed below but none of them would work.

I tried memset
Code:
memset(id, '\0', 50);
but that didn't work.

I tried creating another char[]; and copying its blank contents into the original char
Code:
char idc[50];
char id[50]; //is filled with data
memcpy(id, idc, 50);
but that also didn't work.

I even tried the simple:
Code:
char idc[50];
char id[50]; //is filled with data

id = idc

But of course that wouldn't work (I was desperate).

So I must ask does anyone know how to reset a char pointer array while the Arduino is running without having to reset it?

Thanks, any help would be greatly appreciated!
14  Using Arduino / Storage / Re: Converting a float to a char* for writing to SD card on: May 08, 2013, 08:43:01 pm
Thank you so much to both of you. The solutions that you gave worked just fine and were very helpful!
Once again, Thank You so much!
15  Using Arduino / Storage / Converting a float to a char* for writing to SD card on: May 08, 2013, 06:19:44 pm
Hello so I'm trying to convert a float to a char* to write to an SD card. Here's a simplified example. The problem is that it won't print the float to the SD card, instead it prints two question marks.

Code:

float new_money = 1.0;
char new_money_char[10];
File cust_file;

void setup(){
Serial.begin(9600);
sprintf(new_money_char, "%f", new_money);
cust_file = SD.open("file.txt", FILE_WRITE);
cust_file.write(new_money_char);
cust_file.close();
}


void loop(){
 
}

Any help would be appreciated, thank you!
Pages: [1] 2 3