Using Spark Button and 3.3V LCD screen in Tandem

Hi, so I’m working on a project that uses both the Spark Button and a 3.3 V LCD screen. The project consists of a quick game involving LEDs that, when button 3 on the Spark Button is pressed, goes into a weather mode that connects to an online weather API. I have full functionality of everything else, but as soon as I try to get a read out of the weather from the LCD screen, the entire system seizes. I’ve run the program with both USB connection and with a 6V power source. When the 6V power source is used the system doesn’t seize up anymore but it does get confused and seems to short out at random intervals, on top of that there’s no read out on the screen. Any suggestions? Is it even physically possible to run both the button and and LCD screen? I look forward to everyone’s responses, thanks in advance.

Would you mind posting your code and schematic?

1 Like

Sure, here’s the source code. I’m new to posting code on message boards so please forgive the terrible formatting. For the pin out to the LCD screen I’m using D0,5,6,and 7 and I’m trying to use A0 and A1 as digital pins because the button takes up four of the digital pins. It’s not seizing up anymore but the LCD screen still doesn’t read. Also the On board LED flashes different colors instead of breathing cyan. I’m using a 3.3V LCD from Spark Fun and photo of the circuit is below.

// This #include statement was automatically added by the Spark IDE.
#include "LiquidCrystal/LiquidCrystal.h"

// This #include statement was automatically added by the Spark IDE.
#include "openweathermap.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonValue.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonToken.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonParserBase.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonParser.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonPair.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonObjectIterator.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonObject.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonArray.h"

// This #include statement was automatically added by the Spark IDE.
#include "jsmn.h"

// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"

// This #include statement was automatically added by the Spark IDE.
#include "JsonArrayIterator.h"

// This #include statement was automatically added by the Spark IDE.
#include "SparkButton/SparkButton.h" //import button library

//this module is to create a concept game using the sparkbutton to power LEDs on the ring and interact with them using two of the buttons on the board

//variables for button counter
int count; //variable for count
Weather* weather;
HttpClient* httpClient;
SparkButton b = SparkButton();//claim button object
LiquidCrystal lcd(0, 5, 6, 7, A0, A1);

void setup() 
{
lcd.begin(16,2);
Serial.begin(9600); 
b.begin();//activate button
httpClient = new HttpClient();
    weather = new Weather("Philadelphia,PA", httpClient,
            "8abf01e17a1883e41c73a8f313226678");
    //weather->setCelsius();
    weather->setFahrenheit();
lcd.print("press button 3 for weather");
}


void loop()
{
   lcd.display();
    if (b.buttonOn(3))
    {
        weatherMode();
        lcdWeather();
    }
    else
    {
        gameMode();
    }
}

void gameMode()
{
  
  bool led3 = true; //boolean variables to dictate behavior of lights and interaction
   bool led9 = false; // with buttons
   int n; //light for button 2
   int m; //light for button 4
   int t = 100; //time constant

    


    for(t = 100; t > 5; t--) //speed of light hastens with every cycle
    {
      
        
        if(b.buttonOn(2) && led3 == true) //if button 2 is pressed LEDs bounce from 3 to 9
         {
         for (n=3; n <= 9; n++)
        {
            b.ledOn(n, 0,0,255); //blue led travels
            delay(t);
            b.ledOff(n-1);
            delay(t);
            led9 = true;
            
        }    
         }
        else if(b.buttonOn(4) && led9 == true)//if button 4 is pressed LEDs bounce from 9 to 3
         
         {
    
                for (m = 9; m >= 3; m--)
                {
                    b.ledOn(m, 0,255,0); //green led travels back
                    delay(t);
                    b.ledOff(m+1);
                    delay(t);
                    led9 = false;
                    
                } 
                
            gameCounter(count);
            Serial.println(count);
        
         }
         
    
    else //if player fails to complete cycle, game is over.
    {
        b.allLedsOff();
        break; 
    }
    }
  
}

void weatherMode()
{
    weather_response_t resp = weather->cachedUpdate();
    if (resp.isSuccess) 
    {
        Serial.print(resp.temp_low);
        Serial.print(" - ");
        Serial.print(resp.temp_high);
        Serial.print(" - ");
        Serial.println(resp.descr);
        delay(100);
        
        
        int t = resp.temp_high;        
        if (t > 90)
        {
            b.allLedsOn(55,0,0); //lights are red if temp > 90
        }
        else if ((t < 90) && (t >= 80))
        {
            b.allLedsOn(255,128,0); //lights are orange if 90< temp < 80
        }
        else if ((t < 80) && (t >= 70 ))
        {
            b.allLedsOn(55,55,0); //lights are yellow if 80 < temp < 70
        }
        else if ((t < 70) && (t >= 60))
        {
            b.allLedsOn(0, 55, 0); //lights are green if 70 < temp < 60
        }
        else if ((t < 60) && (t >= 50))
        {
            b.allLedsOn(0, 0, 55); //lights are blue if 60 < temp < 50
        }
        else if((t < 50) && (t >= 32))
        {
            b.allLedsOn(55, 0, 55); //lights are purple if 50 < temp < 32
        }
        else 
        {
            b.allLedsOn(50, 50, 50); //lights are white if temp < 32
        }
    }
}

int gameCounter(int count)
{
    int c;
    
    for (c = 0; c < 1000000; c++)
    {
        count = c;
        return count;
    }
}

void lcdWeather()
{
    lcd.display();
    weather_response_t resp = weather->cachedUpdate();
    if (resp.isSuccess) 
    {
        lcd.print(resp.temp_low);
        lcd.print(" - ");
        lcd.print(resp.temp_high);
        lcd.print(" - ");
        lcd.println(resp.descr);
        delay(100);
    }
}

I ended up switching some things around and I got it.

1 Like

I’m glad you got it working