Announcement

Collapse
No announcement yet.

Screen gives black screen when I turn on the SD module on my arduino.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Screen gives black screen when I turn on the SD module on my arduino.

    Hi hi, people from the good life. I have some problems with combing an SD card module with the screen. The module that I am using is this https://nl.rs-online.com/web/p/memor...E&gclsrc=aw.ds
    I recently used the SD card module myself so I am still new to it, but whenever I activate the SD to write datalog. The screen will not respond after it.
    A quick walkthrough of what I am working on. You start with putting the values of the power supply and it will go to its recommended amps by powering a MOSFET. The SD will write the values of a few sensors.

    The code problems:
    Code:
    #include <genieArduino.h>
    #define RESETLINE 4
    #include <SD.h>
    #include <Wire.h>
    #include <Adafruit_ADS1015.h>
    Adafruit_ADS1115 ads(0x48); // ADC object at I2C address 0x48 for addr pin = GND
    int16_t adc0_1, adc0, adc1, adc2, unoA0; // variables to hold ADC readings
    float multiplier = 0.1875F; // ADS1115 @ +/- 6.144V gain = 0.1875mV/step
    float adcScale = 4.8828F; // Arduino 10 bit @ 5 volts = 4.88mV/step
    Genie genie;
    unsigned long currenttime;
    const int chipSelect = 4;
    int setv;
    float seta;
    float pwma;
    int pwmv;
    int sensv;
    double sensa;
    bool pres;
    bool pres2;
    int pwm = 44; // volt is connected to pin 9
    int MOSFET;
    int maxv = setv+1;
    float maxa;
    float mina;
    int mVperAmp = 100;
    int RawValue= 0;
    int ACSoffset = 2500;
    double Voltage = 0;
    float average = 0;
    // const int chipSelect = 4;
    int inPin = 3; // the number of the input pin
    int outPin = 13; // the number of the output pin
    int stateLED = LOW; // the current state of the output pin
    int reading; // the current reading from the input pin
    int previous = HIGH; // the previous reading from the input pin
    int starttime = 0;
    int printtime = 1000;
    long time = 0; // the last time the output pin was toggled
    long debounce = 200; // the debounce time, increase if the output flickers
    void setup() {
    // put your setup code here, to run once:
    seta;
    Serial.begin(9600);
    Serial1.begin(19200);
    pinMode(53, OUTPUT);
    genie.Begin(Serial1);
    genie.AttachEventHandler(myGenieEventHandler);
    pinMode(RESETLINE, OUTPUT);
    delay(1000);
    digitalWrite(RESETLINE, 1);
    delay(100);
    digitalWrite(RESETLINE, 0);
    delay(3500);
    genie.WriteContrast(10);
    // TCCR5B = TCCR5B & B11111000 | B00000001;
    pinMode(pwm, OUTPUT);
    millis();
    ads.begin(); // init ADS1115 ADC
    }
    void loop() {
    static long waitPeriod = millis();
    genie.DoEvents(); // Run as frequently as possible for best experience
    threshold();
    //Serial.print("Volt:");Serial.print(setv);
    //Serial.print("sensAmp:");Serial.print(sensa);
    // Serial.print("maxAmp:");Serial.print(maxa);Serial.print("minAmp:");Serial.println(mina);Serial.print (" ");Serial.println(MOSFET);
    if (pres == HIGH){
    if (millis() >= waitPeriod)
    {
    // Update the display here
    genie.DoEvents(); // Ensure that this code block only runs after ~100ms
    currentsensor(); //The code for the current sensor
    voltagesensor();
    waitPeriod = millis() + 500; //give the screen time to read it's changes
    }// put your main code here, to run repeatedly:
    }
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, pwmv);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, pwma);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, sensv);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, sensa * 10);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x00, pwmv);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x01, pwma);
    analogWrite(pwm, MOSFET);
    if(pres2==HIGH){
    SDcard();
    }
    }
    void myGenieEventHandler(void){
    genieFrame Event;
    genie.DequeueEvent(&Event);
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 0))
    {
    pwmv++;
    if(pwmv > 100){
    pwmv = 0;
    }
    }
    if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 1)){
    pwmv--;
    if(pwmv < 0){
    pwmv = 100;
    }
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 2))
    {
    pwma++;
    if(pwma > 200){
    pwma = 0;
    }
    }
    if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 3)){
    pwma--;
    if(pwma < 0){
    pwma = 200;
    }
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 7))
    {
    pwmv = 0;
    pwma = 0;
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x00, 0);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x01, 0);
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 6))
    {
    pres2 = HIGH;
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 5))
    {
    pres = LOW;
    MOSFET = 0;
    setv = 0;
    seta = 0;
    maxa = 0;
    mina = 0;
    genie.WriteObject(GENIE_OBJ_FORM, 0x01, true);
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 4))
    {
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, sensv * 26.1);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, sensa * 10);
    genie.WriteObject(GENIE_OBJ_FORM, 0x02, true);
    setv = pwmv;
    seta = pwma/10;
    maxa = seta+0.02;
    mina = seta-0.02;
    pres = HIGH;
    }
    if (Event.reportObject.cmd == GENIE_REPORT_EVENT) {
    if (Event.reportObject.object == GENIE_OBJ_SLIDER) { // If the Reported Message was from a Slider
    if (Event.reportObject.index == 0) { // If Slider1 (Index = 0)
    pwmv = genie.GetEventData(&Event); // Receive the event data from the Slider0
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, pwmv); // Write Slider1 value to LED Digits 0
    }
    else if (Event.reportObject.index == 1) { // If Slider0 (Index = 1)
    pwma = genie.GetEventData(&Event); // Receive the event data from the Slider1
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, pwma); // Write Slider1 value to LED Digits 1
    }
    }
    }
    }
    void SDcard(void)
    {
    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
    //Serial.println("Card failed, or not present");
    // don’t do anything more:
    //return;
    }
    //Serial.println("card initialized.");
    // make a string for assembling the data to log:
    String dataString = "";
    // read three sensors and append to the string:
    for (int analogPin = 0; analogPin < 2; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 1) {
    dataString += ",";
    }
    }
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    // if the file is available, write to it:
    if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
    }
    // if the file isn’t open, pop up an error:
    else {
    Serial.println("error opening datalog.txt");
    }
    }

    full code:
    Code:
    #include <genieArduino.h>
    #define RESETLINE 4
    #include <SD.h>
    #include <Wire.h>
    #include <Adafruit_ADS1015.h>
    Adafruit_ADS1115 ads(0x48); // ADC object at I2C address 0x48 for addr pin = GND
    int16_t adc0_1, adc0, adc1, adc2, unoA0; // variables to hold ADC readings
    float multiplier = 0.1875F; // ADS1115 @ +/- 6.144V gain = 0.1875mV/step
    float adcScale = 4.8828F; // Arduino 10 bit @ 5 volts = 4.88mV/step
    Genie genie;
    unsigned long currenttime;
    const int chipSelect = 4;
    int setv;
    float seta;
    float pwma;
    int pwmv;
    int sensv;
    double sensa;
    bool pres;
    bool pres2;
    int pwm = 44; // volt is connected to pin 9
    int MOSFET;
    int maxv = setv+1;
    float maxa;
    float mina;
    int mVperAmp = 100;
    int RawValue= 0;
    int ACSoffset = 2500;
    double Voltage = 0;
    float average = 0;
    // const int chipSelect = 4;
    int inPin = 3; // the number of the input pin
    int outPin = 13; // the number of the output pin
    int stateLED = LOW; // the current state of the output pin
    int reading; // the current reading from the input pin
    int previous = HIGH; // the previous reading from the input pin
    int starttime = 0;
    int printtime = 1000;
    long time = 0; // the last time the output pin was toggled
    long debounce = 200; // the debounce time, increase if the output flickers
    void setup() {
    // put your setup code here, to run once:
    seta;
    Serial.begin(9600);
    Serial1.begin(19200);
    pinMode(53, OUTPUT);
    genie.Begin(Serial1);
    genie.AttachEventHandler(myGenieEventHandler);
    pinMode(RESETLINE, OUTPUT);
    delay(1000);
    digitalWrite(RESETLINE, 1);
    delay(100);
    digitalWrite(RESETLINE, 0);
    delay(3500);
    genie.WriteContrast(10);
    // TCCR5B = TCCR5B & B11111000 | B00000001;
    pinMode(pwm, OUTPUT);
    millis();
    ads.begin(); // init ADS1115 ADC
    }
    void loop() {
    static long waitPeriod = millis();
    genie.DoEvents(); // Run as frequently as possible for best experience
    threshold();
    //Serial.print("Volt:");Serial.print(setv);
    //Serial.print("sensAmp:");Serial.print(sensa);
    // Serial.print("maxAmp:");Serial.print(maxa);Serial.print("minAmp:");Serial.println(mina);Serial.print (" ");Serial.println(MOSFET);
    if (pres == HIGH){
    if (millis() >= waitPeriod)
    {
    // Update the display here
    genie.DoEvents(); // Ensure that this code block only runs after ~100ms
    currentsensor(); //The code for the current sensor
    voltagesensor();
    waitPeriod = millis() + 500; //give the screen time to read it's changes
    }// put your main code here, to run repeatedly:
    }
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, pwmv);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, pwma);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, sensv);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, sensa * 10);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x00, pwmv);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x01, pwma);
    analogWrite(pwm, MOSFET);
    if(pres2==HIGH){
    SDcard();
    }
    }
    void myGenieEventHandler(void){
    genieFrame Event;
    genie.DequeueEvent(&Event);
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 0))
    {
    pwmv++;
    if(pwmv > 100){
    pwmv = 0;
    }
    }
    if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 1)){
    pwmv--;
    if(pwmv < 0){
    pwmv = 100;
    }
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 2))
    {
    pwma++;
    if(pwma > 200){
    pwma = 0;
    }
    }
    if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 3)){
    pwma--;
    if(pwma < 0){
    pwma = 200;
    }
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 7))
    {
    pwmv = 0;
    pwma = 0;
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x00, 0);
    genie.WriteObject(GENIE_OBJ_SLIDER, 0x01, 0);
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 6))
    {
    pres2 = HIGH;
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 5))
    {
    pres = LOW;
    MOSFET = 0;
    setv = 0;
    seta = 0;
    maxa = 0;
    mina = 0;
    genie.WriteObject(GENIE_OBJ_FORM, 0x01, true);
    }
    if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 4))
    {
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, sensv * 26.1);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, sensa * 10);
    genie.WriteObject(GENIE_OBJ_FORM, 0x02, true);
    setv = pwmv;
    seta = pwma/10;
    maxa = seta+0.02;
    mina = seta-0.02;
    pres = HIGH;
    }
    if (Event.reportObject.cmd == GENIE_REPORT_EVENT) {
    if (Event.reportObject.object == GENIE_OBJ_SLIDER) { // If the Reported Message was from a Slider
    if (Event.reportObject.index == 0) { // If Slider1 (Index = 0)
    pwmv = genie.GetEventData(&Event); // Receive the event data from the Slider0
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, pwmv); // Write Slider1 value to LED Digits 0
    }
    else if (Event.reportObject.index == 1) { // If Slider0 (Index = 1)
    pwma = genie.GetEventData(&Event); // Receive the event data from the Slider1
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, pwma); // Write Slider1 value to LED Digits 1
    }
    }
    }
    }
    void currentsensor(void){
    RawValue = analogRead(0);
    Voltage = (RawValue / 1024) * 5000; // Gets you mV
    sensa = ((Voltage - ACSoffset) / mVperAmp);
    average = average +((Voltage - ACSoffset) / mVperAmp);
    //Serial.print("Raw Value = " ); // shows pre-scaled value
    //Serial.print(RawValue);
    //Serial.print("\t mV = "); // shows the voltage measured
    //Serial.print(Voltage,3); // the '3' after voltage allows you to
    //display 3 digits after decimal point
    Serial.print("\t Amps = "); // shows the voltage measured
    Serial.print(sensa,1); // the '3' after voltage allows you to display
    Serial.print("\t A0");
    Serial.println(A0);
    //3 digits after decimal point
    }
    void voltagesensor(void){
    {
    // read in analog inputs
    adc0_1 = ads.readADC_Differential_0_1(); // read differential AIN0 - AIN1
    adc0 = ads.readADC_SingleEnded(0); // read single AIN0
    adc1 = ads.readADC_SingleEnded(1); // read single AIN1
    adc2 = ads.readADC_SingleEnded(2); // read single AIN2
    unoA0 = analogRead(A0); // read Arduino single A0
    sensv = (adc0 * multiplier)/1000*26.1;
    //Serial.println("V:");Serial.println(adc0 * multiplier);
    }
    }
    void threshold(void){
    if(sensa==seta)
    {
    //Serial.println(MOSFET);
    }
    if(sensa>maxa)
    {
    MOSFET--;
    if(MOSFET<0){
    MOSFET=0;
    }
    }
    if(sensa<mina)
    {
    MOSFET++;
    if(MOSFET>100){
    MOSFET=0;
    }
    }
    // if(setv<sensv){
    // MOSFET=0;
    //
    // }
    }
    void SDcard(void)
    {
    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
    //Serial.println("Card failed, or not present");
    // don’t do anything more:
    //return;
    }
    //Serial.println("card initialized.");
    // make a string for assembling the data to log:
    String dataString = "";
    // read three sensors and append to the string:
    for (int analogPin = 0; analogPin < 2; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 1) {
    dataString += ",";
    }
    }
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    // if the file is available, write to it:
    if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
    }
    // if the file isn’t open, pop up an error:
    else {
    Serial.println("error opening datalog.txt");
    }
    }
    I put a zip file of what I have made for the screen.
    Attached Files
    Last edited by Juliyano satimoen; 24 November 2021, 06:18 PM.

  • #2
    Hi,

    It may be the chip select for the SD card being the same pin as reset. If the reset of the display is on pin 4 then each time the SD card is called then it will reset the display.

    Are you able to move the chipselect pin to another pin ?

    You can prove the issue by changing this,

    const int chipSelect = 4;

    to another value for the pin.

    Best regards

    Paul

    Comment


    • Juliyano satimoen
      Juliyano satimoen commented
      Editing a comment
      Oh yeh... you're right. THANKS! ✧٩(•́⌄•́๑)
Working...
X