Arduino sd card import settings

Hello,

I am working on a small project called "Pin probe" and for the moment if I need to change some setting in the program like names or add more pins I modify the existing one and upload it on the controller. I was thinking maybe I can use the SD shield to insert an sd card that have an txt file on it with my settings. By settings I mean:

Settings

//pins
int probe = 0; //probe
int ledPinFail = 52; //red_led or buzzer "FAIL"
int pSwitch = 53; // Switch

// --- Pins used for testing ---
int nod[48] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };

// --- Pine name definition ---
String nume[]={ "1M","2M","3M","4M","5M","6M","7M","8M","9M","10M","11M","12M","13M","14M","15M","16M","17M","18M","19M","20M","21M","22M","23M","24M",
"1T","2T","3T","4T","5T","6T","7T","8T","9T","10T","11T","12T","13T","14T","15T","16T","17T","18T","19T","20T","21T","22T","23T","24T"};

// --- Definition of connections between pins ---
const int MaxLenNet=5; // pin number of the connection with most pins + 1
String net[][MaxLenNet] = { {"1M","1T"}, {"2M","2T"}, {"3M","3T"}, {"4M","4T"}, {"5M","6M","5T","6T"}, {"7M","7T"}, {"11M","11T"}, {"12M","13M","12T","13T"},
{"14M","14T"},{"15M","15T"},{"16M","16T"},{"17M","17T"}, {"18M","18T"},{"19M","20M","19T","20T"} };

int lennume=sizeof(nume) / sizeof(nume[0]); // Number of pins defined
int lennet=sizeof(net) / sizeof(net[0]); // Number of defined netts

// --- Definition of the colors of wire ---
String culnet[]={ "AbS/Alb", "AbS", "Mar/Alb", "Mar", "Ros+R/A", "Gri/Alb", "Ver/Ng", "Ecranaj",
"Ver/Alb", "Ver", "Mov/Alb", "Mov", "Gri", "Neg+N/A" };

My Code

#include <avr/wdt.h> //autoreset
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27 // I2C Address
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;
int data;
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
//pins
int probe = 0; //probe
int ledPinFail = 52; //red_led or buzzer "FAIL"
int pSwitch = 53; // Switch

// --- Pins used for testing ---
int nod[48] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };

// --- Pine name definition ---
String nume[]={ "1M","2M","3M","4M","5M","6M","7M","8M","9M","10M","11M","12M","13M","14M","15M","16M","17M","18M","19M","20M","21M","22M","23M","24M",
"1T","2T","3T","4T","5T","6T","7T","8T","9T","10T","11T","12T","13T","14T","15T","16T","17T","18T","19T","20T","21T","22T","23T","24T"};

// --- Definition of connections between pins ---
const int MaxLenNet=5; // pin number of the connection with most pins + 1
String net[][MaxLenNet] = { {"1M","1T"}, {"2M","2T"}, {"3M","3T"}, {"4M","4T"}, {"5M","6M","5T","6T"}, {"7M","7T"}, {"11M","11T"}, {"12M","13M","12T","13T"},
{"14M","14T"},{"15M","15T"},{"16M","16T"},{"17M","17T"}, {"18M","18T"},{"19M","20M","19T","20T"} };

int lennume=sizeof(nume) / sizeof(nume[0]); // Number of pins defined
int lennet=sizeof(net) / sizeof(net[0]); // Number of defined netts

// --- Definition of the colors of wire ---
String culnet[]={ "AbS/Alb", "AbS", "Mar/Alb", "Mar", "Ros+R/A", "Gri/Alb", "Ver/Ng", "Ecranaj",
"Ver/Alb", "Ver", "Mov/Alb", "Mov", "Gri", "Neg+N/A" };

int rezultat;
bool fail = false;

// ***** Setting initialization function *****
void setup() {

MCUSR = 0; // clear out any flags of prior resets.
lcd.begin (16, 2); // <<----- My LCD was 16x2 but i would like to change it with 2004 i2c lcd

// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

//setup pins I/O
for (int i = 0; i < 48; i++){
pinMode(nod[i], INPUT_PULLUP);// sets all pins in INPUT_PULLUP (status initial HIGH)
}

pinMode(pSwitch, INPUT_PULLUP); // button mode setting
pinMode(ledPinFail, OUTPUT); // pin / led mode setting Fail

// pinMode(probe, OUTPUT); //work in progress
}

// ***** Functie principala *****
void loop() {
runTest();
}

// ***** Function returning the connection number of the pin if it is free returns -1 *****
int getnet(int pct) {
for(int n=0; n<lennet; n++){
for(int k=0; k<(MaxLenNet+1); k++){

  if (nume[pct]==net[n][k]){
    return(n);
  }
  if (net[n][k] == 0) {break;}
}

}
return(-1);
}

// ***** Running Run Test *****
void runTest() {
lcd.clear();
lcd.print(""); //title
delay(3500);

//user interface
lcd.clear();
lcd.print(""); //main title
lcd.setCursor(0, 1);
lcd.print(""); //title 2

while (digitalRead(pSwitch)) //start testing button

delay(200); //debounce
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Se testeaza..."); //under test message
delay(700);

int netpin;
int jnetpin;
// *** Pin Test Cycle ***
// All existing / defined pins combinations (test each pins with each p pin j then increment i)
for (int i = 0; i < (lennume-1); i++) { // i se va parcurge inclusiv pana la penultimul pin definit
pinMode(nod[i], OUTPUT); // sets the OUTPUT mode for the test pin
digitalWrite(nod[i], LOW); // sets the test LOW pin
netpin=getnet(i);// assign Netpin the net number of the i-pin

  for (int j = i+1; j < lennume; j++) { // pin j starts at pin i + 1 (so omit pins and pins up to i) 
  rezultat = digitalRead(nod[j]); // reads the output on the pin j => j = 0 if it is connected to i and j remains = 1
  jnetpin = getnet(j);
  
  // short circuit test
  if( rezultat==0 && (netpin!=jnetpin || (netpin==-1 && jnetpin==-1)) ){
  // if there is a connection between i and j & pins are defined on different networks; or both pins are "free pins"
    fail=true;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print((String) "ShortC: " + nume[i] + "-" + nume[j]);
    if (netpin!=-1 && jnetpin!=-1){ // Shows the color of the net on line 2 if there are no free pins
      lcd.setCursor(0, 1);
      lcd.print((String) culnet[netpin] + "-" + culnet[jnetpin]);
    }
    else if (netpin==-1 && jnetpin!=-1){
      lcd.setCursor(0, 1);
      lcd.print((String) "Liber-" + culnet[jnetpin]);
    }
    else if (netpin!=-1 && jnetpin==-1){
      lcd.setCursor(0, 1);
      lcd.print((String) culnet[netpin] + "-Liber");
    }
    else{
      lcd.setCursor(0, 1);
      lcd.print((String) "Liber-Liber");
    }
    digitalWrite(ledPinFail, HIGH);
    delay(100);
    digitalWrite(ledPinFail, LOW);
    delay(1000);
    if (digitalRead(pSwitch)==LOW){reset();} // force reset if the button is pressed
  }
  // open circuit test
  if( netpin!=-1 && netpin==jnetpin && rezultat==1 ){
  
    // if the pin is not "free pin" & the pins are defined to be on the same net & they are not
    fail=true;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print((String) "OpenC: " + nume[i] + "-" + nume[j]);
    lcd.setCursor(0, 1);
    lcd.print(culnet[netpin]);
    digitalWrite(ledPinFail, HIGH);
    delay(100);
    digitalWrite(ledPinFail, LOW);
    delay(1000);
    if (digitalRead(pSwitch)==LOW){reset();} // force reset if the button is pressed
  }
}

digitalWrite(nod[i], HIGH); // sets the pin that was tested HIGH
pinMode(nod[i], INPUT_PULLUP);  // switch the test pin mode from OUTPUT to INPUT_PULLUP

}

if (fail) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Cablu DEFECT !"); //Fail cable

//buzzer <<<dummy sound>>>
for(int bz=0; bz<4; bz++){
  digitalWrite(ledPinFail, HIGH);
  delay(200);
  digitalWrite(ledPinFail, LOW);
  delay(50);
  digitalWrite(ledPinFail, HIGH);
  delay(50);
  digitalWrite(ledPinFail, LOW);
  delay(50);
}

}

else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Cablu este BUN"); //Good cable
delay(500);
}
reset();
}

void reset(){
Serial.println();
lcd.setCursor(0, 2);
lcd.print(" Resetare ..."); //reset text
delay(700); //debounce
wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it.
for (;:wink: {
}
}

Pin probe

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x26 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
//pins

int probe = 53; //probe
int mode = 1; // set the mode
int buzz = 52; //buzzer

// --- Pins that are used for testing ---
int nod[49] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};

// --- Name of pins ---
String nume[] = {"M1-B", "M1-C", "M1-E", "M1-F", "M1-H", "M1-J", "M3-B", "M3-C", "M3-E", "M3-F", "M3-H", "M3-J", "M5-B", "M5-C", "M5-E", "M5-F", "M5-H", "M5-J", "M7-B", "M7-C", "M7-E", "M7-F", "M7-H", "M7-J", "M9-B", "M9-C", "M9-E", "M9-F", "M9-H", "M9-J", "M11-B", "M11-C", "M11-E", "M11-F", "M11-H", "M11-J", "M13-B", "M13-C", "M13-E", "M13-F", "M13-H", "M13-J", "M15-B", "M15-C", "M15-E", "M15-F", "M15-H", "M15-J"};

int lennume=sizeof(nume) / sizeof(nume[0]);

void setup() {

MCUSR = 0;  // clear out any flags of prior resets.
lcd.begin (16, 2); //  <<----- My LCD was 16x2

// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home

//setup pins I/O
for (int i = 0; i < lennume+1; i++){
	pinMode(nod[i], INPUT_PULLUP);  //set all pins as input_pullup
}

pinMode(probe, OUTPUT); //set probe output

pinMode(buzz, OUTPUT); //buzzer

}

void loop() {

lcd.clear();
lcd.print(""); //main title 1st row
lcd.setCursor(0, 1);
lcd.print(""); //main title 2nd row

delay(1500);

//Probe
mode = 1;
while (mode == 1) {

//LCD interface 
lcd.clear();
lcd.print("   Probe mode"); //main title
lcd.setCursor(0, 1);
lcd.print("Pin:");
lcd.setCursor(4, 1);

for (int i = 0 ; i < lennume+1; i++) {  //check all pins one by one
    
    //reads the output on the pin and if there is a connection with the probe => i = 0 and displays a message, otherwise i remains = 1
    if( digitalRead(nod[i])==0){
        lcd.print((String) nume[i]);
        
        digitalWrite(buzz, HIGH);
        delay(150);
        digitalWrite(buzz, LOW);
        delay(150);          
        
     }
 }

delay(100);
}
}

Description

So, I got this project "Tester 2.0" for the moment it is made to test a cable that has 2 connectors and each connector has 24 pins. I would like to integrate the "Pin Probe" feature into Tester 2.0, also this new features:

  • the new program it needs to be able to import new settings from sd card, by that I mean this part should be imported from SD
    //pins
    int probe = 0; //probe
    int ledPinFail = 52; //red_led or buzzer "FAIL"
    int pSwitch = 53; // Switch

// --- Pins used for testing ---
int nod[48] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };

// --- Pine name definition ---
String nume[]={ "1M","2M","3M","4M","5M","6M","7M","8M","9M","10M","11M","12M","13M","14M","15M","16M","17M","18M","19M","20M","21M","22M","23M","24M",
"1T","2T","3T","4T","5T","6T","7T","8T","9T","10T","11T","12T","13T","14T","15T","16T","17T","18T","19T","20T","21T","22T","23T","24T"};

// --- Definition of connections between pins ---
const int MaxLenNet=5; // pin number of the connection with most pins + 1
String net[][MaxLenNet] = { {"1M","1T"}, {"2M","2T"}, {"3M","3T"}, {"4M","4T"}, {"5M","6M","5T","6T"}, {"7M","7T"}, {"11M","11T"}, {"12M","13M","12T","13T"},
{"14M","14T"},{"15M","15T"},{"16M","16T"},{"17M","17T"}, {"18M","18T"},{"19M","20M","19T","20T"} };

int lennume=sizeof(nume) / sizeof(nume[0]); // Number of pins defined
int lennet=sizeof(net) / sizeof(net[0]); // Number of defined netts

// --- Definition of the colors of wire ---
String culnet[]={ "AbS/Alb", "AbS", "Mar/Alb", "Mar", "Ros+R/A", "Gri/Alb", "Ver/Ng", "Ecranaj",
"Ver/Alb", "Ver", "Mov/Alb", "Mov", "Gri", "Neg+N/A" };

  • i would like to use an 2004 i2c lcd
  • i would like to give an menu to switch from test in to probe and also in that menu i would like to have a feature that lets me chose what config file i need
  • for navigation i would like to use a rotary encoder or buttons will also work

And also I would like to add a small menu and chose what txt file to use for that time.

I want to mention that so far my code does not include any sd card features or an menu.

If there is someone interested in helping me with this project it will be nice :smiley:

Used Parts

Arduino Mega 2560
Arduino Ethernet Shield with micro SD
Generic Rotary encoder
I wish to change the existing 16x2 lcd with i2c with 2004 lcd also with i2c

Edit update

I update the thread with what I want to do with my project

You need to take the initiative and code up some test examples to figure out what it is you want and how to accomplish it. All kinds of programs use SD cards with files of parameters to control the function of the host program. A search will find them.
Paul

1 Like

Start with something like this:

// --- Pins that are used for testing ---
int nod[200];

// --- Name of pins ---
String nume[200];

int lennume = 0;

Then you open the file and start reading lines:

  while (file.available() && isdigit(file.peek()) && lennume < 200)
  {
    nod[lennume] = file.parseInt(); // Pin number
    nume[lennume] = file.readStringUntil('\n');
    lennume++;
  }
1 Like

Thank you for your replay, I am looking forward and I will try your example this week and I will update this thread :smiley:

there is a "read only" library for ini files
[url]https://github.com/stevemarple/IniFile[/url]

on the other hand, if you want to change the settings on the microcontroller itself, why don't you use EEPROM? EEPROM.put and EEPROM.get is straight forward.
When you bundle all data into a struct, it will get very easy to access one specific value from that struct and/or write a value back to EEPROM.

ps.: please put all your code parts in your first post in code tags to make them readable.

1 Like

Unfortunately I need to close this topic, I no longer need to do this project :frowning:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.