Hi, I have a school project on this year, and i'm at the end of this project.
I need to code a program that display on a OLED screen ( SSD1306 ) the temperature of 2 sensors + if the wire of the printer is detected or not, with an infrared sensor.
My part is to program the display so.
I'm complitly new to ARDUINO so I tried some things, but it's not working, so if you could look at my program..
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int counter = 0;
int infofil = 0;
int infobuse = 0;
int infolit = 0;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
display.setTextSize(1);
display.setTextColor(WHITE);
while(1){
if (infofil=0);
display.setCursor(0,0);
display.println("DETECTION DU FIL=OUI");
display.display();
if (infofil!=0)
display.setCursor(0,0);
display.println("DETECTION DU FIL=NON");
display.display();
infolit = Serial.read();
display.setCursor(0,1);
display.println("TEMPERATURE LIT CHAUFFANT=", infolit);
display.display();
infobuse = Serial.read();
display.setCursor(0,2);
display.println("TEMPERATURE BUSE=" infobuse);
display.display();
}
}
but it's not working
What should it do ?
What does it do ?
Why didn't you Auto Format the code before posting it ?
Why didn't you use code tags when posting it ?
Why do you have a while(1) loop inside the loop() function ?
As I said i'm really new on coding so I don't really know what am I doing, the goal of the project of my team is to improve a 3d printer. Someone is placing 2 temperature sensors ( on the buse and the heated bed ), an other one is taking care of the infrared sensor wich verify that the wire of the printer isn't cut, and my goal is to display on the OLED screen the 2 temperature of the 2 sensors ( I named the variable infobuse and infolit because it's in french so lit=bed ) and the information of the wire ( if the wire is still here or not ).
If I was in class I could verify my program etc.. with arduino + the OLED screen but I'm not in class actually, so I'm just searching here if someone could help me on doing a working program you know.
Here is the code formatted better and in code tags
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int counter = 0;
int infofil = 0;
int infobuse = 0;
int infolit = 0;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop()
{
display.setTextSize(1);
display.setTextColor(WHITE);
while (1)
{
if (infofil = 0);
display.setCursor(0, 0);
display.println("DETECTION DU FIL=OUI");
display.display();
if (infofil != 0)
display.setCursor(0, 0);
display.println("DETECTION DU FIL=NON");
display.display();
infolit = Serial.read();
display.setCursor(0, 1);
display.println("TEMPERATURE LIT CHAUFFANT=", infolit);
display.display();
infobuse = Serial.read();
display.setCursor(0, 2);
display.println("TEMPERATURE BUSE=" infobuse);
display.display();
}
}
Let's start with the easy stuff
if (infofil = 0);
This line of code sets infofil to 0 rather than testing whether it is zero.
Even if you used == instead of = to turn it into a test then the only code depending on its value being zero is the semicolon. I am sure that is not what you meant to happen.
Which lines of code should be executed if infofil is equal to zero ?
How much do you know about programming in C ?
Have you looked at and tried the examples in the IDE ?
Egasnow:
As I said i'm really new on coding so I don't really know what am I doing,
As you wish to implement a moderately complex project I suggest you take some time out to learn the basics. Study some of the examples that come with the Arduino IDE and get familiar with C++ coding.
Then break your project into small parts - for example read a sensor and display the value on the Arduino Serial Monitor, and display "Hello World" on your display screen, etc. Don't try building a composite program until you can do all the parts separately.
...R
Planning and Implementing a Program
Arduino Useful Links