Im make a non-contact temperature devices and using arduino nano, ssh1106 and mlx90614. Im mechanical engineering students and I can't write a code. I take it from chatgpt and this not working.
#include <Wire.h>
#include <SparkFunMLX90614.h>
#include <U8g2lib.h>
// SH1106 OLED with PAGE BUFFER (saves SRAM)
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
// SparkFun MLX90614 object
IRTherm therm;
void setup() {
Wire.begin();
Serial.begin(9600);
delay(500); // Stabilize power before I2C begins
// Initialize OLED early so we can show messages
u8g2.begin();
u8g2.setFont(u8g2_font_6x10_tr);
// Try to begin sensor
if (!therm.begin()) {
Serial.println("MLX90614 not found!");
u8g2.clearBuffer();
u8g2.drawStr(10, 32, "Sensor Not Found!");
u8g2.sendBuffer();
while (1); // Stop execution if sensor fails
}
// Set units to Celsius
therm.setUnit(TEMP_C);
// Show "Sensor OK" message
u8g2.clearBuffer();
u8g2.drawStr(34, 32, "Sensor OK");
u8g2.sendBuffer();
delay(1000);
}
void loop() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tr);
u8g2.drawStr(0, 12, "MLX90614 Temp Readings:");
if (therm.read()) {
float ambient = therm.ambient();
float object = therm.object();
Serial.print("Ambient: "); Serial.print(ambient); Serial.print(" C\t");
Serial.print("Object: "); Serial.print(object); Serial.println(" C");
char buf1[16];
snprintf(buf1, sizeof(buf1), "Ambient: %.1f C", ambient);
u8g2.drawStr(0, 30, buf1);
char buf2[16];
snprintf(buf2, sizeof(buf2), "Object : %.1f C", object);
u8g2.drawStr(0, 46, buf2);
} else {
Serial.println("Sensor read failed!");
u8g2.drawStr(0, 32, "Sensor read failed!");
}
u8g2.sendBuffer();
delay(1000);
}
Instead of ChatGPT that is useless, get a copy of the Arduino Cookbook and read/work your way through that in order to learn how to code for an Arduino. That way you might actually learn something, with AI you learn nothing.
I am confused.
You are a student in school, is that correct?
You have been given an assignment from one of your teachers, is that correct?
Then why do you say your aim is not to learn. If you don't want to learn, don't go to school, if you do want to learn, do the project.
Is that clear, if not what language do you speak and I will have my comments translated for you.
The teacher who gave the project has no idea about the project. I am a mechanical engineering student. I know coding to some extent, but since the first code I wrote did not work correctly, I tried to get help from chatgpt, but it could not do it either. I also showed the electrical engineering teachers at school. No one could fully understand the problem. I wrote to the forum to ask for help, but the topic title I opened was a bit wrong.
As you have seen, ChatGPT does not receive a warm welcome in the forums. Also, it is unlikely that anyone will write the code for you.
I think the first thing you need to do is verify that your hardware is functioning. You can check if the MLX device is functioning by installing this sketch and see if you get the expected output.
It is included in the mlx library and can be installed from the Arduino IDE.
Once you have that working, you must verify that your display works. Here is a tutorial to help with that.
If both devices are functioning, you must figure out how to create the code to satisfy your school project.
If you have specific questions about the code you wrote or the code used in the examples, you will most likely receive a helping hand.
The worst thing you can do is say you don't want to learn. Since your teacher is unhelpful, perhaps you can work with fellow students to learn about Arduino programming.
If you followed the tutorial I mentioned and it still is not working, tell us what display you are using and provide a wiring diagram of how you connected the display to the Arduino.
Also, please tell us if the display is I2C or SPI, what its model number is, and what Arduino model you are using.
This is the first code I wrote, but since I wrote the code for the ssd1306 screen, it was not compatible with the ssh1106 screen. For this reason, I changed the code many times but did not get any results. I had never dealt with Arduino before. I wrote to the forum because I had to. I became more knowledgeable about Arduino than the people around me who said they knew, but I still could not solve the problem.
I compiled the code and it is fine but I don't have that display, too expensive for an 83yo on fixed income.
Since it compiles, you now have to debug it, and that is a different skill set and much more difficult, unfortunately.
A brute force technique is to simply place Serial.println( some variable ); on either side of each statement that may be causing the problem where 'some variable' is some variable that is being used/changed etc.
Good luck.
If you look at this page and scroll down, you will see many versions of the SSH1106 display.
I assume that your instructor or the school provided the display. You need to find out specifically which display it is. Without that knowledge, getting it to work is highly unlikely.
Since I live in Türkiye, I receive an unknown product regardless of where I buy it. The code was written as ssd1306 where I bought it, but since the screen opened with blurred, I thought the screen was broken at first. After 3 weeks of trying, I had 3 times change screens and I thought the error was not in the screen. I soldered the first Arduino nano I bought myself. I thought there was a problem with the solders, this time I bought a soldered Arduino, when the problem continued, I thought the error was in the code and I researched for 2 weeks and constantly changed the code. I used chatgpt in some codes while changing them, I am sorry to used chatgpt. But the problem still hasn't been fixed.
That appears to be a common small I2C OLED display.
What exactly is the project you are expected to do with that display and the IR temp sensor?
If it were me, I would find what library to use for the IR sensor and then use the code from one of the library's examples. I would do the same for the SSH1106. I just looked, and there is one example in one library that is a simple SSH1106 example. Taking out the image code and substituting the IR sensor code is a few minutes of simple work. Good luck, that's more help than I usually give a student.