Code does not work

The cartoon unreal expectations are your own.

If you change those and widen your view including time scale, what you want will be within your grasp.

In the meantime, you only need to know a little C++ for Arduino and should avoid C++ String (and other Container Classes) like the plague.

Learn C first, including C strings. It’s a way shorter study since C is a subset of C++. Arduino IDE compiles C just fine, the book is thin and it includes a whole chapter that the IDE does for you (compile and link) so even shorter.

If you can write Basic or Pascal, the shift to C is even easier.

Using code you don’t understand is how to have bugs you won’t be able to fix but might write in more bugs while trying.

Hi, @smonshmonster
Have you got code that JUST reads one sensor and outputs the result on the IDE Serial Monitor.
Prove you can read the sensor.

chatGPT doesn't even do it in stages.

PLEASE, for the moment forget your main code.
Start writing bits of code for each of your peripherals separately, and get them working.
Then when you have control/comms over all your peripherals;
Put the codes together, ONE at a time, get that combination working;
THEN add another bit of proven code.

Do you see what I am getting at, if you use proven code, you will minimise any bugs as you combine them.

I know this sounds long and laborious, BUT it will minimise your frustration with errors and at the same time get you familiar with Arduino code.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

post#5

post#8

post#9

need to be more like a room full of air pressure sensors in my view

I use ChatGPT, and nearly everytime its code contains bugs, nonsencies or hidden problems.

I can program well, so I am able fix that and I use just small parts of that to solve small parts of problems, but I learned to not trust any word ChatGPT generates and check everything myself.

I programmed lot of big projects and everything I do starts from smaller parts, where I do one simple thing and then I connect more and more parts together.

Your images say, that display doesn’t turn on.

So as first step make “project” with just ESP + display and try display “Hello world” on it - some example should work for it. Then create some variables, set their expected values for your project and display that.

When it works, create another “project” with ESP+one sensor and show measured values over serial connection - when that values looks like it could be usefull (change when you expect to change, stay still when they should not change) try to merge these two projects together and display the values on the display.

Then add the multiplexer and check, that it works for the one sensor, you already tested.

Then add other sensors.

And then add logic to tracking motion.

Poor photos of wiring mess are NOT photos of a hand-drawn wiring diagram. Step one is to remove all but one sensor, then post just that code and just that wiring diagram if it does not work. Once it works you can either add another sensor or do a seperate one sensor setup. Keep doing that until all work now merge them.

If your "drawings" are correct, one reason "code does not work" is that you have an I2C mux, and only connect one I2C device to it, with a second I2C device on a second I2C bus. Use one I2C bus... connected to the TCA... and connect the I2C devices to the TCA

Full error... due to copy/paste losing characters:

sketch.ino: In function 'void setup()':
sketch.ino:117:32: error: expected primary-expression before numeric constant
  117 |   if (!tca.openChannel(uint8_t 0x70 address)) {
      |                                ^~~~
Error during build: exit status 1

The broken function call in your code from the TCA9548A library only wants an eight-bit channel number (0x70) BUT returns NOTHING due to being a VOID function return, so your code will break again when it expects a return boolean. From the library...

void TCA9548A::openChannel(uint8_t channel)
{
    uint8_t buff = 0x00;    
    buff = 1 << channel;
    this->_channels |= buff;

    #if DEBUG
    Serial.print("Open Channel: "); Serial.print(channel); Serial.print(" Data: "); Serial.println(buff);
    #endif  

    write(this->_channels);
}

So, do this:

  tca.openChannel(0x70);

... and POOF... the magic works.

Do you mean the error in line 149? Because I tried that, and it didn't work.

So I couldn't find an example like you said, so I made my own "Hello world!"

Did not work, here's the code:

#include <Arduino.h>
#include <AceWire.h>
#include <TCA9548A.h>
#include <Adafruit_LPS2X.h>
#include <U8g2lib.h>

void setup() {
  // put your setup code here, to run once:
// -------- Display (U8g2 page buffer = AVR friendly) ----------
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

u8g2.setFont(u8g2_font_5x8_tf);

u8g2.setCursor(0, 0);

u8g2.print(F("Hello, world!"));
}

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

Similar issue as before, the display doesn't work.

I will say it was made by cannibalizing the other code. Also couldn't put the code into loop for some reason.

This

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

creates a locally scoped object which would not be visible outside of setup().

You would usually find such a definition outside any function in the up top stuff a sketch can need eveywhere.

a7

Any advice on how to replace it with something else?

Using bits and pieces from the U8g2 library, here is what I came up with:

Code
#include <Arduino.h>
// #include <AceWire.h>
// #include <TCA9548A.h>
// #include <Adafruit_LPS2X.h>
#include <U8g2lib.h>
// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

#define LED_BUILTIN 2

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);

  u8x8.begin();
  u8x8.setPowerSave(0);

  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0,1,"Hello World!");
  u8x8.setInverseFont(1);
  u8x8.drawString(0,0,"0123456789012345");
  u8x8.setInverseFont(0);

  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH); // Allume la LED
  delay(200);                     // Attend une seconde
  digitalWrite(LED_BUILTIN, LOW);  // Éteint la LED
  delay(500);
}

But Adafruit library might be a better choice...

Place such definitions outside any function (in the up top stuff) so the sketch can refer to it eveywhere.

a7

Never mind! I copied the code wrong. But the display is still not displaying anything. But the blue LED is flashing, so that part of the code works.

I have no idea what line 149 is for you. Most do not go by line numbers.

This one,

 if (!tca.openChannel(uint8_t 0x70 address)) {

I posted the correction in Post #28. You never defined "address" and I am not certain type casting an argument when calling a function works. Use the information in Post #28.

It did not work, this is the error I got.

C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino: In function 'void setup()':
C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino:149:22: error: could not convert 'tca.TCA9548A::openChannel(112)' from 'void' to 'bool'
  149 |   if (tca.openChannel(0x70)) {
      |       ~~~~~~~~~~~~~~~^~~~~~
      |                      |
      |                      void
exit status 1

Compilation error: could not convert 'tca.TCA9548A::openChannel(112)' from 'void' to 'bool'

And I changed the code to this.

  if (tca.openChannel(0x70)) {
    u8g2.clearBuffer();
    u8g2.drawStr(0,12,"TCA9548A not found!");
    u8g2.sendBuffer();
    while(1);
  }

Post #28 describes why the compile breaks because of this.

This is trying to change a void (nothing returned) to a bool (if(something) do (something)). So, you must change all the above, to this:

  tca.openChannel(0x70);

Also did not work, here's the error code:

C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino: In function 'void setup()':
C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino:150:3: error: expected primary-expression before 'for'
  150 |   for (uint8_t i=0;i<4;i++) {
      |   ^~~
C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino:147:29: error: expected ')' before 'for'
  147 |   if (tca.openChannel(0x70);
      |      ~                      ^
      |                             )
......
  150 |   for (uint8_t i=0;i<4;i++) {
      |   ~~~                        
C:\Users\Erik\Downloads\sketch_aug25a\sketch_aug25a.ino:150:20: error: 'i' was not declared in this scope
  150 |   for (uint8_t i=0;i<4;i++) {
      |                    ^
exit status 1

Compilation error: expected primary-expression before 'for'

It also broke a completely different line of code somehow.