Sorry I’ve got an adblocker on, I didn’t realise it was a bad site. I can’t attach the files as this forum only allows JPG and PNG and GIF, but I can paste them here. I’ll include the .ino as well since that’s where the compiler error is pointing:
WeatherStation.ino
#include "ILI9163.h"
#include "Ubidots.h"
#include "Adafruit_Sensor.h"
#include "Adafruit_BME280.h"
#define WHITE rgb(255, 255, 255) //Some basic colours
#define BLACK rgb(0, 0, 0)
#define RED rgb(255, 0, 0)
#define GREEN rgb(0, 255, 0)
#define BLUE rgb(175, 175, 255)
#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5 //These are not needed as we're using i2c for BME not SPI
#define SEALEVELPRESSURE_HPA (1013.25)
#define tempoffset -0.9 //BME temp sensor is always high by this amount
#define TOKEN "ix9hooYdMoBXnxoCNP65gUTNKjBG1S" // Ubidots stuff
Ubidots ubidots(TOKEN);
Adafruit_BME280 bme; // initialize BME sensor over I2C
ILI9163 tft = ILI9163(A2, D4, D6); // TRY to initialize LCD
int timer1 = 20; // How often to send sensor updates to Ubidots
void setup() {
RGB.control(true); //Turn off Photon's pulsing blue LED
tft.fill(rgb(0, 0, 0)); //Clear LCD
tft.copy_buffer();
Serial.begin(9600); //Removing the serial stuff breaks everything, leave it
Serial.println(F("BME280 test"));
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.println(); //Leave this serial too
float pres1; //Read BME sensors
pres1 = (bme.readPressure() / 100.0F);
float temp1;
temp1 = (bme.readTemperature() + tempoffset);
float hum1;
hum1 = bme.readHumidity();
timer1 -= 1; //Start counting down to next Ubidots updates
tft.fill(rgb(0, 0, 0)); //Draw neat stuff on the LCD
tft.set_cursor(0, 0);
tft.set_color(WHITE, BLACK);
tft.print("TEMPERATURE, HUMIDITY& PRESSURE - by moe");
tft.println("");
tft.println("");
tft.set_color(RED, BLACK);
tft.print("T: ");
tft.print(temp1);
tft.print((char)248);
tft.println("C");
tft.println("");
tft.set_color(BLUE, BLACK);
tft.print("H: ");
tft.print(hum1);
tft.println("%");
tft.println("");
tft.set_color(GREEN, BLACK);
tft.print("P: ");
tft.print(pres1);
tft.println(" mBar");
tft.println("");
tft.println("");
tft.set_color(WHITE, BLACK);
tft.print("Time til update: ");
tft.print(timer1);
tft.println("s");
tft.copy_buffer();
if (timer1 < 1) { //Update Ubidots with sensor data
ubidots.add("Temperature", temp1);
ubidots.add("Humidity", hum1);
ubidots.add("Pressure", pres1);
ubidots.sendAll();
timer1 = 20;
}
delay (1000); //Update the screen once per second
}
ILI9163.cpp
#include "ILI9163.h"
#include "glcdfont.cpp"
#include <stdint.h>
#include "Particle.h"
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#define fontx 5
#define fonty 7
// Private
void ILI9163::write_command(uint8_t cmd) {
digitalWrite(a0, LOW);
digitalWrite(cs, LOW);
SPI.transfer(cmd);
digitalWrite(cs, HIGH);
}
void ILI9163::write_data(uint8_t data) {
digitalWrite(a0, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(data);
digitalWrite(cs, HIGH);
}
void ILI9163::write_data16(uint16_t data) {
digitalWrite(a0, HIGH);
digitalWrite(cs, LOW);
SPI.transfer((data >> 8) & 0xff);
SPI.transfer(data & 0xff);
digitalWrite(cs, HIGH);
}
void ILI9163::set_address(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
write_command(ILI9163_CMD_SET_COLUMN_ADDRESS);
write_data16(x1);
write_data16(x2);
write_command(ILI9163_CMD_SET_PAGE_ADDRESS);
write_data16(y1 + 32);
write_data16(y2 + 32);
write_command(ILI9163_CMD_WRITE_MEMORY_START);
}
// Public
ILI9163::ILI9163(int _cs, int _rst, int _a0) : Adafruit_GFX(ILI9163_WIDTH, ILI9163_HEIGHT) {
cs = _cs;
rst = _rst;
a0 = _a0;
cursor_x = 0;
cursor_y = 0;
fg_color = rgb(255, 255, 255);
bg_color = fg_color;
SPI.begin(cs); // Start SPI
SPI.setBitOrder(MSBFIRST);
// Setup pins
pinMode(rst, OUTPUT);
pinMode(a0, OUTPUT);
// Reset display
digitalWrite(rst, HIGH);
delay(5);
digitalWrite(rst, LOW);
delay(20);
digitalWrite(rst, HIGH);
delay(150);
// Init sequence
write_command(ILI9163_CMD_EXIT_SLEEP_MODE);
delay(120); // Wait for the screen to wake up
for (size_t i = 0; i < sizeof(init_sequence)/sizeof(uint8_t); i++) {
if (init_sequence[i] == 0xff) {
i++;
write_command(init_sequence[i]);
} else {
write_data(init_sequence[i]);
}
}
}
void ILI9163::fill(uint16_t color) {
for (int i = 0; i < ILI9163_WIDTH * ILI9163_HEIGHT * 2; i += 2) {
buffer[i] = (color >> 8) & 0xff;
buffer[i + 1] = color & 0xff;
}
}
void ILI9163::drawPixel(uint8_t x, uint8_t y, uint16_t color) {
if ((x < 0) || (x >= ILI9163_WIDTH) || (y < 0) || (y >= ILI9163_HEIGHT)) return;
buffer[(x + y*ILI9163_WIDTH)*2] = (color >> 8) & 0xff;
buffer[(x + y*ILI9163_WIDTH)*2 + 1] = color & 0xff;
}
/*void ILI9163::draw_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
draw_pixel(x0 , y0+r, color);
draw_pixel(x0 , y0-r, color);
draw_pixel(x0+r, y0 , color);
draw_pixel(x0-r, y0 , color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
draw_pixel(x0 + x, y0 + y, color);
draw_pixel(x0 - x, y0 + y, color);
draw_pixel(x0 + x, y0 - y, color);
draw_pixel(x0 - x, y0 - y, color);
draw_pixel(x0 + y, y0 + x, color);
draw_pixel(x0 - y, y0 + x, color);
draw_pixel(x0 + y, y0 - x, color);
draw_pixel(x0 - y, y0 - x, color);
}
}
void ILI9163::draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
_swap_int16_t(x0, y0);
_swap_int16_t(x1, y1);
}
if (x0 > x1) {
_swap_int16_t(x0, x1);
_swap_int16_t(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
for (; x0<=x1; x0++) {
if (steep) {
draw_pixel(y0, x0, color);
} else {
draw_pixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}*/
void ILI9163::clear() {
fill(rgb(0, 0, 0));
set_cursor(0, 0);
}
/*void ILI9163::draw_char(uint8_t x, uint8_t y, char c, uint16_t col, uint16_t bg) {
if(x >= ILI9163_WIDTH || y >= ILI9163_HEIGHT || (x + fontx) < 0 || (y + fonty) < 0)
return;
for(int8_t i = 0; i < (fontx + 1); i++ ) {
uint8_t line;
if(i < fontx) line = pgm_read_byte(font+(c*fontx)+i);
else line = 0x0;
for(int8_t j = 0; j < (fonty + 1); j++, line >>= 1) {
if(line & 0x1) {
draw_pixel(x+i, y+j, col);
} else if(bg != col) {
draw_pixel(x+i, y+j, bg);
}
}
}
}
/*size_t ILI9163::write(uint8_t c) {
if (c == '\n') {
cursor_y += (fonty + 1);
cursor_x = 0;
} else if (c == '\r') {
// skip em
} else {
if((cursor_x + (fontx + 1)) >= ILI9163_WIDTH) { // Heading off edge?
cursor_x = 0; // Reset x to zero
cursor_y += (fonty + 1); // Advance y one line
}
draw_char(cursor_x, cursor_y, c, fg_color, bg_color);
cursor_x += (fontx + 1);
}
return 1;
}*/
void ILI9163::set_cursor(uint8_t x, uint8_t y) {
cursor_x = x;
cursor_y = y;
}
void ILI9163::set_color(uint16_t fg, uint16_t bg) {
fg_color = fg;
bg_color = bg;
}
void ILI9163::copy_buffer() {
set_address(0, 0, ILI9163_WIDTH - 1, ILI9163_HEIGHT - 1);
digitalWrite(a0, HIGH);
digitalWrite(cs, LOW);
SPI.transfer(buffer, NULL, sizeof(buffer)/sizeof(uint8_t), NULL);
digitalWrite(cs, HIGH);
}
ILI9163.h
#ifndef _ILI9163_
#define _ILI9163_
#include <stdint.h>
#include "Particle.h"
#include "Adafruit_mfGFX.h"
#define ILI9163_WIDTH 128
#define ILI9163_HEIGHT 128
#define ILI9163_CMD_NOP 0x00
#define ILI9163_CMD_SOFT_RESET 0x01
#define ILI9163_CMD_GET_RED_CHANNEL 0x06
#define ILI9163_CMD_GET_GREEN_CHANNEL 0x07
#define ILI9163_CMD_GET_BLUE_CHANNEL 0x08
#define ILI9163_CMD_GET_PIXEL_FORMAT 0x0C
#define ILI9163_CMD_GET_POWER_MODE 0x0A
#define ILI9163_CMD_GET_ADDRESS_MODE 0x0B
#define ILI9163_CMD_GET_DISPLAY_MODE 0x0D
#define ILI9163_CMD_GET_SIGNAL_MODE 0x0E
#define ILI9163_CMD_GET_DIAGNOSTIC_RESULT 0x0F
#define ILI9163_CMD_ENTER_SLEEP_MODE 0x10
#define ILI9163_CMD_EXIT_SLEEP_MODE 0x11
#define ILI9163_CMD_ENTER_PARTIAL_MODE 0x12
#define ILI9163_CMD_ENTER_NORMAL_MODE 0x13
#define ILI9163_CMD_EXIT_INVERT_MODE 0x20
#define ILI9163_CMD_ENTER_INVERT_MODE 0x21
#define ILI9163_CMD_SET_GAMMA_CURVE 0x26
#define ILI9163_CMD_SET_DISPLAY_OFF 0x28
#define ILI9163_CMD_SET_DISPLAY_ON 0x29
#define ILI9163_CMD_SET_COLUMN_ADDRESS 0x2A
#define ILI9163_CMD_SET_PAGE_ADDRESS 0x2B
#define ILI9163_CMD_WRITE_MEMORY_START 0x2C
#define ILI9163_CMD_WRITE_LUT 0x2D
#define ILI9163_CMD_READ_MEMORY_START 0x2E
#define ILI9163_CMD_SET_PARTIAL_AREA 0x30
#define ILI9163_CMD_SET_SCROLL_AREA 0x33
#define ILI9163_CMD_SET_TEAR_OFF 0x34
#define ILI9163_CMD_SET_TEAR_ON 0x35
#define ILI9163_CMD_SET_ADDRESS_MODE 0x36
#define ILI9163_CMD_SET_SCROLL_START 0x37
#define ILI9163_CMD_EXIT_IDLE_MODE 0x38
#define ILI9163_CMD_ENTER_IDLE_MODE 0x39
#define ILI9163_CMD_SET_PIXEL_FORMAT 0x3A
#define ILI9163_CMD_WRITE_MEMORY_CONTINUE 0x3C
#define ILI9163_CMD_READ_MEMORY_CONTINUE 0x3E
#define ILI9163_CMD_SET_TEAR_SCANLINE 0x44
#define ILI9163_CMD_GET_SCANLINE 0x45
#define ILI9163_CMD_READ_ID1 0xDA
#define ILI9163_CMD_READ_ID2 0xDB
#define ILI9163_CMD_READ_ID3 0xDC
#define ILI9163_CMD_FRAME_RATE_CONTROL1 0xB1
#define ILI9163_CMD_FRAME_RATE_CONTROL2 0xB2
#define ILI9163_CMD_FRAME_RATE_CONTROL3 0xB3
#define ILI9163_CMD_DISPLAY_INVERSION 0xB4
#define ILI9163_CMD_SOURCE_DRIVER_DIRECTION 0xB7
#define ILI9163_CMD_GATE_DRIVER_DIRECTION 0xB8
#define ILI9163_CMD_POWER_CONTROL1 0xC0
#define ILI9163_CMD_POWER_CONTROL2 0xC1
#define ILI9163_CMD_POWER_CONTROL3 0xC2
#define ILI9163_CMD_POWER_CONTROL4 0xC3
#define ILI9163_CMD_POWER_CONTROL5 0xC4
#define ILI9163_CMD_VCOM_CONTROL1 0xC5
#define ILI9163_CMD_VCOM_CONTROL2 0xC6
#define ILI9163_CMD_VCOM_OFFSET_CONTROL 0xC7
#define ILI9163_CMD_WRITE_ID4_VALUE 0xD3
#define ILI9163_CMD_NV_MEMORY_FUNCTION1 0xD7
#define ILI9163_CMD_NV_MEMORY_FUNCTION2 0xDE
#define ILI9163_CMD_POSITIVE_GAMMA_CORRECT 0xE0
#define ILI9163_CMD_NEGATIVE_GAMMA_CORRECT 0xE1
#define ILI9163_CMD_GAM_R_SEL 0xF2
#define rgb(r, g, b) (((((uint8_t)b)>>3) << 11) | ((((uint8_t)g)>>2) << 5) | (((uint8_t)r)>>3))
class ILI9163 : public Adafruit_GFX {
public:
uint8_t buffer[ILI9163_WIDTH * ILI9163_HEIGHT * 2] = {0};
ILI9163(int _cs, int _rst, int _a0);
void fill(uint16_t color);
void drawPixel(uint8_t x, uint8_t y, uint16_t color);
// void draw_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
//void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void clear();
//void draw_char(uint8_t x, uint8_t y, char c, uint16_t col, uint16_t bg);
virtual size_t write(uint8_t c);
void set_cursor(uint8_t x, uint8_t y);
void set_color(uint16_t fg, uint16_t bg);
void copy_buffer();
private:
uint8_t init_sequence[83] = {
0xff, ILI9163_CMD_SET_PIXEL_FORMAT, 0x05,
0xff, ILI9163_CMD_SET_GAMMA_CURVE, 0x04,
0xff, ILI9163_CMD_GAM_R_SEL, 0x01,
0xff, ILI9163_CMD_POSITIVE_GAMMA_CORRECT, 0x3f, 0x25, 0x1c, 0x1e, 0x20, 0x12, 0x2a, 0x90, 0x24, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, ILI9163_CMD_NEGATIVE_GAMMA_CORRECT, 0x20, 0x20, 0x20, 0x20, 0x05, 0x00, 0x15, 0xa7, 0x3d, 0x18, 0x25, 0x2a, 0x2b, 0x2b, 0x3a,
0xff, ILI9163_CMD_FRAME_RATE_CONTROL1, 0x08, 0x08,
0xff, ILI9163_CMD_DISPLAY_INVERSION, 0x07,
0xff, ILI9163_CMD_POWER_CONTROL1, 0x0a, 0x02,
0xff, ILI9163_CMD_POWER_CONTROL2, 0x02,
0xff, ILI9163_CMD_VCOM_CONTROL1, 0x50, 0x5b,
0xff, ILI9163_CMD_VCOM_OFFSET_CONTROL, 0x40,
0xff, ILI9163_CMD_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x00, 0x7f,
0xff, ILI9163_CMD_SET_PAGE_ADDRESS, 0x00, 0x00, 0x00, 0x7f,
0xff, ILI9163_CMD_SET_ADDRESS_MODE, 0x00,
0xff, ILI9163_CMD_SET_DISPLAY_ON,
0xff, ILI9163_CMD_WRITE_MEMORY_START
};
int cs, rst, a0;
uint8_t cursor_x, cursor_y;
uint16_t fg_color, bg_color;
void write_command(uint8_t cmd);
void write_data(uint8_t data);
void write_data16(uint16_t data);
void set_address(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
};
#endif