Receiving an Error with Raspberry Pi board

Hi, I am in desperate need of help with a project that I’m working on to build a soil moisture sensor and I’ve been stuck because of an error that I’m getting.

Hardware: Raspberry Pico and OLED display.

Full message error
fatal error: pgmspace.h: No such file or directory
#include <pgmspace.h>
^~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Raspberry Pi Pico.

have a look at how-to-get-the-best-out-of-this-forum
in particular

  1. give details of the sensors you are using?
  2. have you tested the sensors using seperate programs?
  3. upload the complete program which gave you the error - use code tags, e.g. select < CODE/ > and paste text where it says “type or paste code here”
  4. where did you get the program from ?
  5. upload a schematic showing how you wired the systems and powered it

it could be that the program you are attempting to use was implemented for a particular microcontroller and will not build on a RPi Pico - question 4 above should clarify this

avoid uploading screen images - they waste a lot of space and are impossible to copy code from - upload text using code tags

2 Likes

Thank you for that here is a bit more detail and someone on GitHub said, “ I can tell you're not using this core, first of all (there are normally ~8 options listed on the bottom status line, not just RPI Pico on X ). You're using the Arduino MBED one which does not support that header, evidently. You should head over there for more assistance since it seems they don't have a pgmspace.h header.”

  1. I am using a capacitive moisture sensor V2.0 and OLED LCD Display.

  2. I have tested the raspberry pico using a different program and it was flashing it worked however when trying to program the OLED display I am receiving an error. The capacitive sensor does also work I programmed it using the Raspberry Pico.

  3. Here is the program code (sorry I tried using the code button but doesn't seem to organize it)
    '/*
    Soil Moisture Meter
    soil_meter.ino
    Measures percentage of moisture in soil
    Uses Capacitive sensor
    Requires calibration values

DroneBot Workshop 2022
https://dronebotworkshop.com
*/

// Include required libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Set OLED size in pixels
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Set OLED parameters
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Sensor constants - replace with values from calibration sketch

// Constant for dry sensor
const int DryValue = 2590;

// Constant for wet sensor
const int WetValue = 1430;

// Variables for soil moisture
int soilMoistureValue;
int soilMoisturePercent;

// Analog input port
#define SENSOR_IN 0

void setup() {

// Setup Serial Monitor
Serial.begin(9600);

// Initialize I2C display using 3.3-volts from VCC directly
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay();

// Set ADC to use 12 bits
analogReadResolution(12);

}
void loop() {

// Get soil mositure value
soilMoistureValue = analogRead(SENSOR_IN);

// Print to serial monitor
Serial.print(soilMoistureValue);
Serial.print(" - ");

// Determine soil moisture percentage value
soilMoisturePercent = map(soilMoistureValue, DryValue, WetValue, 0, 100);

// Keep values between 0 and 100
soilMoisturePercent = constrain(soilMoisturePercent, 0, 100);

// Print to serial monitor
Serial.println(soilMoisturePercent);

// Position and print text to OLED
display.setCursor(20, 0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println("Moisture");

display.setCursor(30, 40);
display.setTextSize(3);
display.setTextColor(WHITE);
display.print(soilMoisturePercent);
display.println("%");
display.display();

delay(250);
display.clearDisplay();

delay(100);
}`

  1. I got the program from DroneBot Workshop on YouTube
    YouTube link: https://youtu.be/pgGpuws7f9o?si=T4SWRrMpYHMliXjI
    Article with code link:
    Water Your Garden with IoT | DroneBot Workshop

The code was written for an AVR processor, with limited RAM. It will need to be modified for the Pico.

Please edit your posts to add code tags, and use code tags in the future.

2 Likes

I tried modifying it a bit but it doesn’t seem to work. Do you have any suggestions specifically?

For help, please post the complete code showing the problem, using code tags. Also post the complete error messages, using code tags.

1 Like

The error message is here, "C:\Users\letew\OneDrive\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:42:10: fatal error: pgmspace.h: No such file or directory
#include <pgmspace.h>
^~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Raspberry Pi Pico." It would be great if you can help since my project is due this week and getting the OLED display to work is my finally part.

  Soil Moisture Meter
  soil_meter.ino
  Measures percentage of moisture in soil
  Uses Capacitive sensor
  Requires calibration values
 
  DroneBot Workshop 2022
  https://dronebotworkshop.com
*/
 
// Include required libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
// Set OLED size in pixels
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
 
// Set OLED parameters
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
// Sensor constants - replace with values from calibration sketch
 
// Constant for dry sensor
const int DryValue = 2590;
 
// Constant for wet sensor
const int WetValue = 1430;
 
// Variables for soil moisture
int soilMoistureValue;
int soilMoisturePercent;
 
// Analog input port
#define SENSOR_IN 0
 
void setup() {
 
  // Setup Serial Monitor
  Serial.begin(9600);
 
  // Initialize I2C display using 3.3-volts from VCC directly
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  display.clearDisplay();
 
  // Set ADC to use 12 bits
  analogReadResolution(12);
 
}
void loop() {
 
  // Get soil mositure value
  soilMoistureValue = analogRead(SENSOR_IN);
 
  // Print to serial monitor
  Serial.print(soilMoistureValue);
  Serial.print(" - ");
 
  // Determine soil moisture percentage value
  soilMoisturePercent = map(soilMoistureValue, DryValue, WetValue, 0, 100);
 
  // Keep values between 0 and 100
  soilMoisturePercent = constrain(soilMoisturePercent, 0, 100);
 
  // Print to serial monitor
  Serial.println(soilMoisturePercent);
 
  // Position and print text to OLED
  display.setCursor(20, 0);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Moisture");
 
  display.setCursor(30, 40);
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.print(soilMoisturePercent);
  display.println("%");
  display.display();
 
  delay(250);
  display.clearDisplay();
 
  delay(100);
}

The Adafruit_SSD1306 graphics library is evidently not designed to be used with the Pico.

Post on the Adafruit forum and ask if there is a suitable alternative.

1 Like

Thank you thank you so much, I really appreciate your help! I was able to find a suitable alternative using chatgpt which was U8g2 and everything works now including the LCD display.

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