Hi. I want to make two sensors work on one board. I use UNO R4 minima and mlx90614 and BMP280.
For I2C, there is only one set of SDA/SCK(A4 and A5), I have to use both sensors in one set but I can't find how to make a code with a parallel circuit.
As SPI, I already use my d11,12,13 pin. So I want to make another dig pin as MISO, MOSI, SCK and use them, but I can't find how to do so.
Regardless of the method, I wish I could receive two sensor values โโfrom one board.......
I am sooo newbie to this and my head is really confused now. My search skill now reach the limit......... I desperately need your help. What should I do? Any answer will be very helpful.
BMP280 can have either SPI or i2c, but many breakout modules allow only i2c. But that's fine.
I recommend using i2c for both. Connect them to the same pins. The two devices have different addresses. Probably the Arduino libraries you will use with them will take care of the addressing for you. It should be easy.
Well... if you use i2c for both sensors like I suggested, you won't need the SPI library.
Your code does not seem to use an RTC, so perhaps you don't need that library either.
You seem to be using the DHT library, but there is no code in your sketch for that either. DHT sensors can measure humidity, which BMP280 cannot, but if you had chosen BME280, there would be no need for the DHT sensors also because BME280 can measure temperature, humidity and pressure.
As a real beginner if you put together code that uses more than one sensor before even starting testing. In your case you are using
MLX
BMP
RTC
SD card
DHT
There are not only 4 places where a bug could be there are
4 * 4 * 4 * 4 * 4 = 1024 places where a bug could be.
Now estimate how long does it take to test your complete code until you have tested for 1024 potential bugs?
It is well invested time to save a lot of time to develop code in small steps.
Where you write a testcode for one component and immidiately test if this one component works.
If this works add a second component and do the same procedure again.
Your project will be up and running 3 times faster if you develop your code this way step by step
There is one step about making each piece then combining them.
What works One Thing At A Time by forcing delays/wait-for's will have to be changed to only make itself wait, it takes practice to really get
understanding what blocks smooth, timely execution of void loop().
knowing the code techniques to unblock execution.
And then the sketches can combine and name/resource clashes be resolved.
I2C can take around 80-100 ms to get a response to a request, I know from millis-stamped log lines. Read characters as they arrive, don't wait for whole transmissions but rather monitor many in the same period.
When you don't block, it's possible without stretching an Uno.
I find the overview with tabs feel I'm in charge of the code. Sure there's a limit where it goes out of hand as well, to put all blocks of code in their own tabs won't do any good.
How do you get a good overview over the code yourself?
There is one more lesson to combine with do many things at once (watch a burron and blink a led) and that lets a process be done as steps small enough to not block and able to be finished over many loop() runs.
Think of void loop() as a wheel. Every time it goes around some time passes and some steps of multiple tasks get done even if the step is to not be triggered and not do something yet. Just rolling along, that's automation.
The first step is to use sensible function names so that their purpose is more obvious. Secondly functions should do one thing rather than several, even if that means having more functions. Most, functions of the sketch when running are called from loop() so that becomes the point of reference. Thus loop() calls the functions in a particular order which defines the structure of the sketch
Of course, none of the above precludes the use of tabs , but because IDE 2.x allows you to easily jump to a function or variable definition whether they are in separate tabs or in the main .ino file does not really matter. As an extension to this, it does not matter whether the function that you want to see is part of your own sketch or in a library #included in it, you can jump to it in the same way
1.x tabs had some weird compile twist, IIRC was Java related.
I hadn't thought but with 2.x can source .c or .cpp files #include as if typed in there where I want? And not have to extern vars? Combine code (but not the .ino) without copy and paste or making everything a library?
That can be workable. It's code-toolbox-friendly at the filename level.