Arduino support for the ESP32-S2 is relatively new right now, so we recommend using CircuitPython!

Once you have Arduino installed and set up and you can upload simple blink sketches, you can move on to using each element of the FunHouse board.

Using the Red LED

It's always good to blink the LED when you want to verify if something is happening on your board. The LED is on IO #13, but we recommend you use the LED_BUILTIN macro and you can use this simple sketch example to blink the LED:

void setup() {
  // initialize built in LED pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize USB serial converter so we have a port created
  Serial.begin();
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

Reading the Buttons

There are three buttons on the front of the FunHouse - they're connected to digital pins IO 3, 4, and 5. However, we recommend you use the constants BUTTON_DOWN, BUTTON_SELECT, BUTTON_UP.

void setup() {
  Serial.begin(115200);
  
  pinMode(BUTTON_DOWN, INPUT_PULLDOWN);
  pinMode(BUTTON_SELECT, INPUT_PULLDOWN);
  pinMode(BUTTON_UP, INPUT_PULLDOWN);
}

void loop() {
  if (digitalRead(BUTTON_DOWN)) {
    Serial.println("Down Button pressed");
  }
  if (digitalRead(BUTTON_SELECT)) {
    Serial.println("Select Button pressed"); 
  }
  if (digitalRead(BUTTON_UP)) {
    Serial.println("Up Button pressed");  
  }

  // small debugging delay
  delay(10);
}

Open the serial console and press buttons to see the serial output printed!

Reading the Capacitive Touch Pads

To read the value of the capacitive touch pads, you can use the touchRead() function, which is part of the ESP32 package. To use it, you only need to provide the GPIO pin number. The FunHouse uses IO #6, #7, and #8 for the button style touch pads and #9 through #13 along the slider.

So to get the value of IO #7, you would use the following code:

uint16_t touchread;

touchread = touchRead(7);
if (touchread > 20000 ) {
  // Do Something
}

You may want to try adjusting the threshold for your needs. A more complete example can be found on the Arduino Self Test Example page.

Using On-Board DotStars

There are 4 DotStar LEDs on pin IO #14 and #15 (we recommend using the macro PIN_DOTSTAR_DATA and PIN_DOTSTAR_CLOCK). 

Here's an example sketch that initializes the DotStar LEDs and color cycles them through a rainbow of different colors.

#include <Adafruit_DotStar.h>

#define NUM_DOTSTAR 5

// LEDs!
Adafruit_DotStar pixels(NUM_DOTSTAR, PIN_DOTSTAR_DATA, PIN_DOTSTAR_CLOCK, DOTSTAR_BRG);

uint16_t firstPixelHue = 0;
uint8_t LED_dutycycle = 0;

void setup() {
  Serial.begin(115200);
  
  pinMode(LED_BUILTIN, OUTPUT);
  
  ledcSetup(0, 5000, 8);
  ledcAttachPin(LED_BUILTIN, 0);
  
  pixels.begin(); // Initialize pins for output
  pixels.show();  // Turn all LEDs off ASAP
  pixels.setBrightness(20);
}



void loop() {
  Serial.println("Hello!");

  // pulse red LED
  ledcWrite(0, LED_dutycycle++);

  // rainbow dotstars
  for (int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
      int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels());
      pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue)));
  }
  pixels.show(); // Update strip with new contents
  firstPixelHue += 256;

  delay(15);
}


void rainbow(int wait) {
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
      int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels());
      pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue)));
    }
    pixels.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}

Using On-board Humidity and Temperature Sensor

There's a pre-soldered humidity and temperature sensor that you can use.

You can test the AHTX0 by loading the included adafruit_aht_test in the Arduino library

Now you can upload, reset, and check the serial port for temperature and humidity data!

Using On-board Pressure Sensor

There's a pre-soldered pressure sensor that you can use.

You can test the DPS310 by loading the included adafruit_sensor_test in the Arduino library

Now you can upload, reset, and check the serial port for ambient temperature and pressure data!

Using the TFT Display

You've been so patient, it's time to draw to the display!

We'll be using a demo that was written for the HalloWing M4, which has the same display, so only a couple of minor changes are needed.

From the Adafruit ST7735 and ST7789 Library folder, open the graphicstest_hallowing_m4 example

Remove the pin definitions near the top since they are now part of the FunHouse Board Support Package.

#define TFT_CS        44 // PyBadge/PyGamer display control pins: chip select
#define TFT_RST       46 // Display reset
#define TFT_DC        45 // Display data/command select
#define TFT_BACKLIGHT 47 // Display backlight pin

Change the initialization line to the following:

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RESET);

You can now upload the example to your FunHouse to see it display various graphics and text tests.

For more information on how to display graphics, and text, check out the Adafruit GFX guide

This guide was first published on Apr 20, 2021. It was last updated on 2021-05-04 15:26:05 -0400.

This page (Arduino Basics) was last updated on May 04, 2021.

Text editor powered by tinymce.