Notifications
Clear all

OLED display and am2320 adafruit sensor  


Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

I must declare here I find the forum structure a little complex for my ageing brain. However, I seek help and hope I'm in the right place. Ive previously used the am2320 to display its output on the serial monitor, and also succesfully run the adafruit test display on the OLED 128 x 32.

so far so good, but trying to follow the video of

"

OLED Displays with Arduino - I2C & SPI OLEDs"

has failed so far.

just beginning the sketch it stops with error of

"expected ')' before ';' token"

here is the code as far as that point, if anyone can see the obvious error then please let me know?

//Include wire library for i2c
#include <Wire.h>;
#include <Adafruit_GFX.h>;
#include <Adafruit_SSD1306.h>;
#define OLED_RESET 4;

please accept my apologies if I've put this post in the wrong place..

 

Graham


Quote
noweare
(@noweare)
Trusted Member
Joined: 12 months ago
Posts: 98
 

Hello Graham, Remove the semi-colons from the #include and #define statements.


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare many thanks,.....much appreciated


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare after removing the semicolons i get as far as this line

Adafruit_AM2320 am2320 = Adafruit_AM2320();

but it returns a "does not name a type message" and " did I mean Adafruit_SSD1306"

hmm....painful progress......that line appears to match the code given in the tutorial, is it perhaps the libraries are a problem?

Ah, I have tried naming a type for Adafruit_AM2320 and calling it a float. That only moves the problem along to a message of "expected initializer before am2320"

hmmm....Im clearly not understanding this session, and would appreciate any help to point me backto a more basic example or tutorial guys....

sorry

graham

This post was modified 2 months ago 2 times by Graham410

ReplyQuote
noweare
(@noweare)
Trusted Member
Joined: 12 months ago
Posts: 98
 

First try this example located at :

Always try to start with working code. Add a little of your code, then test and then move on. Small steps and checking as you go works best.


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare Many thanks I will do as you suggest....

 


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare HI, ok, I have copied and pasted that code into the IDE and it compiled and uploaded fine. the resulting readings are displaying on the serial monitor. my next step is now how to write them to the oled...


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

Hi again, Ive taken the code that was working for reading the serial monitor and added to it in line with the sketch given in the tutorial. checking it would compile at each stage, and came to this part

#include "Adafruit_Sensor.h"
#include "Adafruit_AM2320.h"
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

Adafruit_AM2320 am2320 = Adafruit_AM2320();

void setup() {
Wire.begin();
display.begin(SSD1306_SWITCHCAPVV, 0x3C); this line gives the error not declared in this scope. I'll return to this tomorrow, thank you for your help.


ReplyQuote
noweare
(@noweare)
Trusted Member
Joined: 12 months ago
Posts: 98
 

Hello Graham, here are some examples for the OLED. Just choose the example

for your display size.

https://github.com/adafruit/Adafruit_SSD1306/tree/master/examples


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare hi, thank you for your reply, ive opened that link and chose the second line of examples....after copying and pasting the code into a blank sketch I ran compile and it stopped at this line:

@@ -60,7 +61,7 @@ void setup() {

and thenm gave an error saying "stray @ in prgram"

hmm.......Ive written code for many examples previously but never used the @ symbol.

perhaps I should copy the full page of code in here..

 

// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES 10 // Number of snowflakes in the animation example
@@ -60,7 +61,7 @@ void setup() {
Serial.begin(9600);

// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

 

thank you.

oh, Ive just read down the page you linked to, and come across this;

Preferred installation method is to use the Arduino IDE Library Manager. To download the source from Github instead, click "Clone or download" above, then "Download ZIP." After uncompressing, rename the resulting folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h.

Ive not been doing that, but just copying and pasting, so i will download the zip file instead and try follow the instructions..

yes I downloaded the zipfile file but it hasnt helped me...

as a simple step ive selected the 128x32 examples file for the 1306 and it runs fine showing the animation.

i know I can load the temp and humidity into the serial monitor ok...so the hardware seems ok. But still back where I began by needing to read data and print to oled..i guess it must be rather trying the patience of those trying to help when folk just dont seem to get it lol..

thank you

This post was modified 2 months ago 2 times by Graham410

ReplyQuote
noweare
(@noweare)
Trusted Member
Joined: 12 months ago
Posts: 98
 

@graham410  I don't see the @@symbols when I look at the code in github. You get that from copy and pasteing from the browser into your editor. Better off downloading the code first then copy to your sketch folder.

Try using this. I got this from the example you got working. It should print "scroll" on the screen. Just call it from Loop() and it should print "scroll" to the display.

void testscrolltext(void) {
display.clearDisplay();
 
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("scroll"));
display.display(); // Show initial text

delay(100);

}

Anything you want to print on the screen has to be formatted as text first. So if you have a number like 14.32 a float stored in the variable myfloat the code would be.

sprintf(buffer,"%f",myfloat);

Serial.print(buffer);

You have to #include <stdio.h>

 

Hope that helps

 

 


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare hi, im making a little progress with another tutorial i found using the DHT22 sensor. it has code that at least produces the temperature reading on both a 128 x 32 and 128 x 64 OLED that I have. However the screen only displays the temp and not the humid value, still its progress.

I hadnt realised that what you send as a print has to be in "" even if its a float value, thank you for that.

I will stick with the code I in the DHT example and change/adapt it, in small steps to develop my understanding.

I'm sure I have an enormous lack of knowledge of functions, classes, objects etc that is preventing me from understanding it, and I'm going to need to follow up on that.

 

thank you for your kind help.

Graham.

 


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

hi again, I'm learning from tweaking the code in my example. At present I've succeeded in adapting it to print me the humidity, instead of the temp, and varying font sizes etc and positions of cursor. So far Ive been unable to get both humid and temp onto the same screen but no matter, at least im making progress.

im curious to know how folks know to enter a line into the code such as this

display.begin(SSD1306_SWITCHCAPVV, 0x3C)

Do you get that from the library routines or some other source, it may seem like a naive question but it utterly baffled me when dronebot simply adds it in...

 

regards

graham


ReplyQuote
noweare
(@noweare)
Trusted Member
Joined: 12 months ago
Posts: 98
 

You can look at the code to see what is being done in the begin method. I normally just start with a working example which always has xxx.begin() method so it's not something I have to remember.

I think that just initializes the display. I am not a C++ guy just C. Begin is a method, otherwise know as a function, of the display object.

Remember, nearly all of what we use is open source. So a library will come with an *.h file and a *.cpp file. Many of the authors will place documentation in those files as well, so you can peruse those files to see how the underlying code works and the methods available to you.

Anyways, learn how to use the sprintf function it is an easy way to change things to strings for printing.

Glad your found a decent example. Text displays would be easier to use in your project rather than a graphical display.

~Joe


ReplyQuote
Graham410
(@graham410)
Eminent Member
Joined: 1 year ago
Posts: 23
Topic starter  

@noweare thank you for your time Joe


ReplyQuote