does it have some practical application?
That is what I asked, so why ask me the question?
I was expecting you to tell me what this was.
I mean, it is connected to the computer. I want it to work via play/record. It works without the computer by rotating the data stored in the sd card.
@sadk_sadk Your other topic on the same subject How to (record and play) data posted using a different username has been closed and the account has been suspended
Why did you start a new topic with a new username ?
I didn't get more people in the post so I did it
@sadk_sadk is enjoying a short break from the forum
Posting an obscure picture is NOT telling me anything. I can't even make out what it is supposed to be.
You don't seem very good at cooperating. We can't read your mind, we only know what you tell us, and so far you have told us very little.
Anyway I have already told you how to do it, which you seem to have ignored.
If I had known before, I would have done this,
binary 11000000
hexadecimal C0
Byte (0-255) 192
Sent from Visual Basic to Arduino À
00111000
38
56
8
01110000
70
112
p
11100000
E0
224
à
This reading line by line
I don't know how to merge between two programs
#include <SD.h>
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
I found an example but the data is called only the stock in the sd card is not recording from the serial port, (the LCD is not needed)
#include <SD.h>
#include <EEPROM.h>
#include <SD.h>
String buffer;
int latchPin = 5 ; // Pin connected to ST CP of 74HC595
int clockPin = 7 ; // Pin connected to 58 CP of 74HC595
int dataPin = 6 ; //// Pin connected to 05 of 74HC595
/// POTENTIOMETER FOR TIME DELAY ////////////////////
const int PotTime = A1 ;
int Potvalue = 0 ; // The actual Fot value
int PotmapValue=100 ;// Mapped output value milisecond
// LCD STUFF
#include <LiquidCrystal.h>
// Pines para el LCD
#define LCD_RS A5
#define LCD_Enable 9
#define LCD_D4 2
#define LCD_D5 3
#define LCD_D6 4
#define LCD_D7 8
//Initialize
LiquidCrystal lcd(LCD_RS,LCD_Enable,LCD_D4,LCD_D5,LCD_D6,LCD_D7);
/*----------BUTTON DECELERATION-----------*/
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
/*---------(Deklarasi varibel) -----------*/
int lcd_key = 0 ;
int adc_key_in =0 ;
int adc_key_prev = 0 ;
int read_LCD_buttons ()
{
adc_key_in=analogRead ( A0 ) ;
// delay ( 5 ) ;
// int k = ( analogRead ( A0 )_adc_key_in ) ;
// if ( 5 < aba ( k ) ) return btnNONE ;
if ( adc_key_in > 1000 ) return btnNONE ;
if ( adc_key_in < 50 ) return btnRIGHT ;
if ( adc_key_in < 195 ) return btnDOWN;
if ( adc_key_in < 380 ) return btnSELECT ;
if ( adc_key_in < 555 ) return btnUP ;
if ( adc_key_in < 790 ) return btnLEFT ;
return btnNONE ;
}
boolean Nextfile =false ;
boolean Previousfile = false ;
/*////LETS DEFINE THIS SKETCH FOR NIMSER OF SOLENOID VALVE
1 mean 8 Solenoid valves
2 means n×8 solenoid valves */
int solenoid =1 ;// change this number to run more then 8 valve
// READ FILE STATISICS I
int Total_number_of_lines = 0 ;
boolean WrongbyteData = false ;
///////// SD BELATED STUFF // mmmmmm
File sd_root ;
File sd_file ;
#define max_name_len 13
#define max_num_Files 40
unsigned char num_Files= 0 ;
unsigned char current_File = 0 ;
char file_Name [ max_name_len ] ; // fn
#define sd_cs 10 // chip select ' line for the microad card
void sd_card_setup ()
{
if (!SD.begin(sd_cs))
{
//lcd.clearDisplay ( ) ;
Serial.println ( " sd card failed \ nor not present " ) ;
//lcd.display ( ) ;
return ;
}
sd_root=SD.open ("/") ;
//Serial.println("sd card root open " ) ;
if (!sd_root)
{
//lcd.clearDisplay ( ) ;
Serial.println ( " ad card failed \ nor not present " ) ;
//lcd.display ( ) ;
return ;
}
}
/*//*IETS UPLOAD ALL 40 FILES TO EEPROM. *
* *THIS TO BE CHECKED EACH TIME WE LORD THE SD CARD
*WEMOST HAVE A FUNCTION TO ERASE THE MEMORY I THINK
* IRPUTURE E MILL CECK THE CONTET OF EACH FILE AND DISCARD THE FILE BASED ON WRONG BYTES DATA m */
void sd_dir_setup ()
{
num_Files = 0;
// sd_root = SD.open ("/");
sd_root.rewindDirectory ();
while (num_Files < max_num_Files)
{
//break out of while loop when we check all file (past the last entry).
File entry =sd_root.openNextFile();
boolean EndofLine=false;
//Serial.peint (entry.name ());
if (!entry)break;
// Serial.print (num_Files);
//Serial.print (entry.name() ) ;
WrongbyteData=false;//Make ie false for every new file
//LETS SEE THE CONTENTS OF FILE SUITABLE AND DISCARD IF RONE BYTE DATA
while (entry.available ()>0) //read from the file until there's nothing else in it:
{
buffer = entry.readStringUntil('\n');
//read uptil new 1ine character meet i.e. Line by Line
Serial.print (buffer);
// Serial.printin("Buffer Length: ");
//Serial.print (buffer.length()-1);
if ((buffer.length ())==1)
{
Serial.println("End of Line Detected");
EndofLine =true;
goto lup1;
}
if (((buffer.length()-1)!=solenoid)&&(EndofLine==false))
{
Serial.println("wrong File");
WrongbyteData=true;
// entry.close ();
}
}
lup1:
if (entry.name () [0] == '-' ||entry.name() [0]=='-' || entry.isDirectory ())
{
continue ;
}
char i ;
for (i=max_name_len - 5;i> 0;i--)
{
if (entry.name () [i] =='-') break;
}
i++ ;
/*This only stoe *.KFK FILES IN EEPROM (for now)
if you add other file types. you should add their extension here. */
if (( entry.name()[i]='T' && entry.name()[i+1] =='X'&& entry.name()[i+2]=='T')&& WrongbyteData==false) //||(p.name ()[i]=='W '&& p.name () [i+1]=='A'&& p.name () [i+2] =='V'))
{
for (char i= 0;i<max_name_len; i++)
{
EEPROM.write (num_Files*max_name_len + i, entry.name () [i]);
}
// Serial.printin("EEPROM WRITTEN"):
num_Files++;
}
}
}
/*/
GET THE FIE A FRON EEISON
*/
void get_current_File_as_fn()
{
for (char i=0; i< max_name_len; i++)
{
file_Name [i] =EEPROM.read (current_File *max_name_len + i);
}
Serial.println (file_Name);
}
/*//
OPEN THE FIle TO RUN
*/
void sd_file_open()
{
get_current_File_as_fn(); //Takeout the file name from EEPROM
sd_file=SD.open (file_Name, FILE_READ) ;
}
// Serial.printin(sd_file);
//prant_title to_lcd();
/*//CHECK COTENT AND DISCARD IF WRONO BYTE DATA, NO ENTRY IN EEPROM*/
/*void Check_file()
while (printin . available())// read from the file untal there's nothing else in it:
{
buffer =sd_file.readSteingUnital('\n'): read uptil new line character meet i.e. Line by Line E ((buffer.length( )-1 !=solenoid) {
Serial.printin(This fountain can only operates 8 valves-SD Card file error:
sd file.close();
wrongbyteData=true;//Send back RETULRNING LETS EMPTY ALL THE SHIFTREGISIERS
return;}}}*/
/* DESIGH FILE STATES*/
//DIR PLAY=PLAY_ALL
//ME3_PLAY = FLAY_SINGLEmp3play()==play_Single
enum state{ PLAY_ALL, PLAY_SINGLE, PAUSED };
state current_state=PLAY_ALL;
void Play_Single()
{
int i;
while (sd_file.available())/// read from the file until there's nothing else in it:
{
buffer=sd_file.readStringUntil ('\n');
//Read uptil new line character meet i.e. Line by Line
/*if (buffer.length()-1)!= solenoid){
Serial.printin("This fountain can only operates 8 valves-sd Card File error")
sd_file.close();
//SEFORE RETURING LEIS ENTRY ALL THE SHIFTEGISTERE I
emptyshiftRegister ();
return;}
/*/
PollKeys();
PotDelay ();//This will get the PotmapValue for use in shift register
if (Nextfile==true)
{
Nextfile=false;
emptyShiftRegister ();
sd_file.close ();
Next_File();
return;
}
if (Previousfile==true)
{
Previousfile=false;
emptyShiftRegister ();
sd_file.close ();
Previous_File ();
//Previous File();//DO'T KOW NHY IT REQUIRED TO MAKE TWICE
return;
}
/*// LETS SEGEGATE THE SITES IN EACH LINE AND SEND to MICROcoTROLLES /*/
byte bytes[buffer.length()];// Store Byte data in Array of number of bytes in line
buffer.getBytes(bytes, buffer.length ()+1);
//Serial.printin(( buffer.getBytes (bytes, buffer.length()+1)) );
digitalWrite (latchPin, 0); //Lets start sending one lines byte data to Shift Register
for (int i=0;i<buffer.length();i++);
{
Serial.println(bytes[i],DEC);
shiftOut(dataPin, clockPin, (char)bytes[i]);
//LETS LATCHLIN "ON" ONLY WHEN THE LAST BYTE FED TO THE shiftout FUNCTION. LETS VERIFY IN FOLLONING
if (i==buffer.length ()-1);// WE KNOE THE BUFFER LENGTH HAS ONE EXTRA BYTE OF " /n" so LETS HEGATE IT
{
digitalWrite (latchPin, 1);
delay (PotmapValue);///Delay Based on potentiometer value
}
}
}//end of while loop
sd_file.close ();// AS file is completly read and sent to the controller so close it
if (current_state==PLAY_SINGLE)
{
emptyShiftRegister();
current_state== PAUSED;
}
}//end of function
void Play_All ()
{
if (sd_file)
{
Play_Single ();
}
else
{
if (current_File < (num_Files - 1))
{
current_File++;
sd_file_open ();
}
else
{
current_File =0;
sd_file_open ();
current_state==PAUSED;
}
}
}
void Play_Pause ()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time =millis ();
//If interrupta come faster than 200ms, assume it's a bounce and ignoce
if (interrupt_time - last_interrupt_time > 200)
{
if (current_state==PLAY_ALL)
{
current_state=PAUSED;
}
else
{
current_state = PLAY_ALL;
}
}
last_interrupt_time = interrupt_time;//digitalWrite (pin, LOW);
}
void Next_File()
{
static unsigned long last_interrupt_time=0;
unsigned long interrupt_time=millis();
//If interrupta come faster than 200ms, assume it's bounce and ignore
if (interrupt_time -last_interrupt_time > 200)
{
sd_file.close () ;
current_state=PLAY_ALL;
}
last_interrupt_time - interrupt_time;//digitalWrite (pin, LOW);
}
void Previous_File ()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis ( );
// If interrupta come faster than 200ms, assume it's a bounce and ignore
if ( interrupt_time - last_interrupt_time > 200 )
Serial.println ( " HOLLA " ) ;
{
sd_file.close ( ) ;
if ( current_File==0 )
{
current_File=num_Files - 2 ;
}
else
{
current_File=current_File-2 ;
}
current_state=PLAY_ALL ;
}
last_interrupt_time=interrupt_time ; // digitalWrite ( pin , LOW ) ;
}
void setup ()
{
Serial.begin (9600);
pinMode (sd_cs, OUTPUT);
// SD.begin (sd_cs);
pinMode (latchPin, OUTPUT);
//vol - mp3 vol;
//lcd.begin (50);
//lcd.print ("Barebones Mp3");
//led.display();
//Mp3.begin (mp3_cs, mp3_dcs, mp3_rst, mp3_dreq);
// Mp3. volume (vol);
lcd.begin(20, 4);
sd_card_setup();
sd_dir_setup ();
sd_file_open ();
Splash_LCD_lst();
delay (1000);
Splash_LCD_ReadFiles ();
delay (1000) ;
Splash_LCD_ReadFiles_insequence ();
delay (1000);
get_current_File_as_fn();
}
/*attachinterrupt (2, playpause , FALLING); attachinterrupt (0, NextSong, FALLING); attachinterrupet (1, Previousong, FALLING ); pinMode (buttonpin1. INPUT);
pinMode (buttonpin2. INPUT);
/Genotronex.begin (9600);*/
/*//HERE 15 THE TH LOOP FUNCTION /*/
void loop ()
{
// Serial.printin(current_state);
current_state=PLAY_ALL;
// Pollkeys ();
//Serial.printin(current_state );
Main_LCD ();
switch (current_state)
{
case PLAY_ALL:
//Pollkeya ();
Play_All();
break;
case PLAY_SINGLE:
Play_Single ();
break;
case PAUSED:
// Pollkeya ();
break;
}
/*lup1;
menu();
lup2//*/
/*buttonstate1= digitalRead (buttonPin1);
if (buttonistat1==HIGH){
if(vol<254){
vol=vol++;}}
buttonstate2= digitalRead (buttonPin2);
if (buttonistat2==HIGH){
if(vol>0){
vol=vol--;}}*/
/*if(Genotronex.available()){
BluetoothDeta-Genotrenex.read (); if(BluetoothDate=='1'){//if number 1 predsed.. Previousong();
Genotronex.printin("Going back to the previous song.");}
if(BluntoothData=='2'){// if number 0 pressed.. playPause();
Genotronex.priatin("play/pause song.");}
if ( BluetoothData=='3' ){ // if number 0 pressed ....
NextSong ( ) ;
Genotronex.priatin ( " Going to the next song " );}
if( BluetoothData=='='){ // if number 1 pressed
if ( vol<254 ){
vol =vol +10 ;
Genotronex.priatin ( " Volume Increased " ) ;
}} If( BluetoothData=='-'){// if number 1 pressed ....
if( vol>0 ){
vol =vol -10 ;
Genotronex.priatin ( " Volume Decreased " ) ;}}} Mp3. volume ( vol);*/
}
/*void menu(){
Icd.setCursor (0,0); lcd.print("1.Single File"); lcd. setCursor (0, 1); lcd.print("2.All File");
lcd. setCursor (0, 2); lcd.print("3.Time delay ");
Icd. setCursor (0,3); lcd.print(" 3.Read Temp");}*/
void emptyShiftRegister ()
{
digitalWrite (latchPin, 0);//Lets start sending to Shift Regiater
for (int i=0;i<solenoid+1;i++)
{
shiftOut(dataPin, clockPin, 0x00);
// LETS LATCHPIN "ON"ONLY WHEN THE LAST BYTE FED TO THE shittout FUNCTION. LETS VERIFY IN FOLLOWING
if (i==solenoid); //WE KNOW THE BUFFER LENGTH HAS ONE EXTRA BYTE OF " /n" SO LETS NEGATE IT
{
digitalWrite (latchPin, 1);
delay (1000);
}
}
}
void shiftOut (int myDataPin, int myClockPin, byte myDataOut)
{
//This shifta e bite out MSS first,
//on the rising edge of the clock,
//clock idles lov /internal function setup
int i=0;
int pinState;
pinMode (myClockPin, OUTPUT);
pinMode (myDataPin, OUTPUT);
//Clear everything out juat in case to
//prepare shift regiater for bit shifting
digitalWrite (myDataPin, 0);
digitalWrite (myClockPin, 0);
//for each bit in the byte my dataout
//NOTICE THAT WE ARE COUNTINS DOWN in our for loop
//This means that %100000001 or 1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--)
{
digitalWrite (myClockPin, 0);
//if the value passed to myDetaout and a bitmask result
//true then. .. so if we are at i=6 and our value is
//%11010100 it would the code compares it to 0100000
// and proceeda to set pinState to 1.
if( myDataOut &(1<<i))
{
pinState=1;
}
else
{
pinState= 0;
}
//Seta the pln to HIGH er LOR depending an pinstate
digitalWrite (myDataPin, pinState);
//register ahifts bita on upstroke of clock pin
digitalWrite (myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite (myDataPin, 0);
}
//stop shifting
digitalWrite (myClockPin, 0);
delay (1);
}
/*void print title_to_lcd(){
get_title_from_id3tag ();
lcd.cleardisplay();
lcd.printin(title);
Lcd. display();}*/
///LCD STUFF
void SD_error_LCD()
{
lcd.setCursor (0, 4);
lcd.print ("SD Card Not Found. ..");
}
void Splash_LCD_lst()
{
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ("Graphical Waterfall");
lcd.setCursor (0, 1);
lcd.print (" By ");
lcd. setCursor (0, 2);
lcd.print (" khalid khattak ");
lcd.setCursor (0, 3);
lcd.print (" +92-0300 7061499 ");
}
void Main_LCD()
{
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ("File :");
lcd.setCursor (6, 0);
lcd .print (file_Name);
lcd.setCursor (0, 1);
lcd.print ("Status:");
if (current_state==0)
{
lcd. setCursor (8, 1);
lcd.print ("Play All" );
}
else if (current_state==1)
{
lcd. setCursor (8, 1);
lcd.print ("Play Single");
}
else if (current_state==2)
{
lcd.setCursor (8, 1);
lcd.print ("Pause");
}
//led.setCursor (0, 1);
// led.print(" By ");
// led.setCuraor (0, 2);
// led.print (" By khalid Khattak "); //Potmapvalue
lcd. setCursor (0, 3);
lcd.print ("T-Files:");
lcd.setCursor (8, 3);
lcd.print (num_Files);
lcd. setCursor (11 , 3);
lcd.print ("Time:");
lcd.setCursor (16, 3);
lcd.print (PotmapValue);
}
void Splash_LCD_ReadFiles()
{
lcd.clear ();
lcd.setCursor (0, 1);
lcd.print ("Reading SD Card.....");
lcd.setCursor (0, 2);
lcd.print ( "Total Files : ");
lcd.setCursor (15, 2);
lcd.print (num_Files);
lcd.setCursor (0, 3);
lcd.print ("No. of values: ");
lcd.setCursor (16 , 3);
lcd.print (solenoid*8);
}
void Splash_LCD_ReadFiles_insequence ()
{
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print (" Now Playing ");
lcd. setCursor (0, 1);
lcd.print (" All Files");
lcd .setCursor (0, 2);
lcd.print (" in ");
lcd.setCursor (0, 3);
lcd.print (" back to back ");
}
void PotDelay()
{
Potvalue = analogRead (PotTime);
// map it to the range of the analog out:
PotmapValue =map (Potvalue, 0, 1023, 0, 255);
// change the analog out value:
//Serial.printin (Pormapvalue);
// wait 2 milliseconds before the next loop
//for the analog-to -digital converter to settle
// Serial.println (PotmapValue);
// vait 2 milliseconda before the next loop
// tor the analog-to-digital converter to settle
// after the last reading:
delay (2);
}
void PollKeys()
{
adc_key_prev = lcd_key ; // Melihat perbedaan
lcd_key = read_LCD_buttons ();//baca tombol
if (adc_key_prev != lcd_key)
{
Serial.println ("Different key Selected");
switch (lcd_key)
{
// depending on which button was pashed, we perform an action
case btnRIGHT:
{
Serial.println("Right Button Preased");
/* led.clear();
tampl_waktu() ;
delay (5000);
goto lup1*/
break ;
}
case btnLEFT:
{
Previousfile =true;
//Serial.printin("Previous Button Pressed"); lcd.clear();
/*lcd.setCursor (0,0); lcd.print ("READ EEFROM ");
for (int i=0;i<256 ;i++)
{
detaku=eeprom_12c_read(alamat_ EEPROM, i);
delay(50)
lcd.setCursor (0,1); lcd.print ("Address: 0×" );lcd.prant(i, HEX);
lcd.setCursor(-4,2);lcd.print ("Data: 0×"); lcd.print(" dataku, HEX")
delay(1000);
}
delay(1000);*/
break;
}
case btnUP:
{
Serial.println("Up Button Pressed");/*
Icd.clear();
Lcd.print ("WRITE EERON");
for (int i=0;i<256;i++)
{
eeprom_i2c_write(alamat EEPROM, i,i);
}
delay(1000);*/
break;
}
case btnDOWN:
{
Serial.println("Next Button Pressed");
Nextfile=true;
/*Lcd.clear();
beca_suhu( );
delay (2000); */
break;
}
case btnSELECT:
{
Serial.println("Select Button Pressed");
/* lcd. clear();
Simpan_MMC();
delay(4000) ;*/
break;
}
case btnNONE:
{
//go to lup1;
}
}
}
}
Well that is quite a heap of code. In the schematic I can't see any power and ground to the SD card and also I can't see anything connected to DO.
So when this sort of thing happens it is best to start simple. Just write some code that writes four numbers into a file and then closes the file. Put it in the setup function and have a blank loop function so you don't write too much data uncontrollable.
When you get this working add on the end of the setup function something to open the file and print out the four numbers (bytes) in the file.
Does this work?
Depends on what you mean by work. It looks like it will do what it is designed to do, which is read an SD file and write it out to the 74HC595. Note this shift register is an output only, I think this is half of what you want to do.
To read button pushes you need another type of shift register one that is parallel in and serial out. Or a much more complex type of shift register that will do both jobs.
To record, read the data from the DS of 74HC595
int dataPin = 11;
And what puts the data into the shift register in the first place in order for you to read it from the serial pin?
SH-CP timing for shift
register (second SP-CP to pass the latch clock for the stored logs
I take a step back and I have one wire to record
serialInArray[serialCount] = Serial.read(); // read a byte sent by processing
You seem to have learn nothing.
This is getting nowhere, I am putting this thread on mute for me.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.