hi,
iam working on application for alarm with esp32 and esp idf framework with i2c sensor using i2cdev driver (https://github.com/UncleRus/esp-idf-lib)
so i want to develop esp32 board with i can connect until 8 i2c sensor and i can connect the same device with the same adresse at the same time so iam using software i2c for each socket i have BUS i2c with different pin SCL/SDA .
so all work well try to connect 8 bme280 at same time i can print all data and i can detect type of sensor witch is connected to socket that work with i2cscanner and i can create table of sensor found .
the problem is i need to collect data with one file json for all sensor to send it with mqtt (mqtt send work)
how i can do that from table of sensor found bcs this table change (one sensor ,5 sensor,3sensor,..max 8 and the same sensor or not)
some one can can help me to find the best method to create json file depend table of device found , how i can change json in terms of number and type of sensor connect and i want send data each 10s and when the value change with 5 unity (dont wait 10s to send data i need send it immediately )
application for alarm project collect data
application for alarm project collect data
- Attachments
-
- Capture.PNG (382.85 KiB) Viewed 6650 times
Last edited by mohasrj on Fri Jul 17, 2020 4:01 pm, edited 2 times in total.
Re: application for alarm project collect data
There is something like I2C expander. You can connect more than one i2c slave on the same line:
https://www.ti.com/lit/ds/symlink/tca95 ... e.com%252F
It is popular IC, so you will find a lot materials.
Re: application for alarm project collect data
yes i try with it it work but its more difficult to manage it but u select one device at the same time ... so is not that the problem whit software i2c that work well , but how i can collect data dynamically (if i have one sensor i send data for one sensor if i have 5,3 or 8 ...)
Re: application for alarm project collect data
With software i2c you can read 1 device at the time too. Eventually 2 devices if you use 2 cores, but you have 2 hardware i2c on esp32.
For sure you cant read 8 devices at the same very moment.
It was just suggestion, nothing more.
For sure you cant read 8 devices at the same very moment.
It was just suggestion, nothing more.
Re: application for alarm project collect data
yes but iam using FreeRTOS library and software i2c with i2cdev driver i start 8 task at the same time in one core u think is the same if i use one task to read them ? that not take more time , but i work with alarm project i need detect quickly any change value ?
http://www.chibios.com/forum/viewtopic. ... a&start=10
https://microcontrollerslab.com/arduino ... resources/
http://www.chibios.com/forum/viewtopic. ... a&start=10
https://microcontrollerslab.com/arduino ... resources/
Re: application for alarm project collect data
esp32 has only 2 cores, that means you can run at most 2 tasks at the same time, other tasks are awaiting to resume.
They will be switching in round robin, assuming that all tasks are with the same priority (i2c tasks).
You are only complicating your code and life, because its easier to maintain 1 task (or 2) if you cant run more than 2 tasks simultaneously.
Now, is another thing. If you want to run 2 tasks on 2 cores in exactly the same time you will have to synchronize with semaphores or tasknotify.
You can do a simple test with 8 tasks blinking 8 leds and use logic analyzer to see results.
They will be switching in round robin, assuming that all tasks are with the same priority (i2c tasks).
You are only complicating your code and life, because its easier to maintain 1 task (or 2) if you cant run more than 2 tasks simultaneously.
Now, is another thing. If you want to run 2 tasks on 2 cores in exactly the same time you will have to synchronize with semaphores or tasknotify.
You can do a simple test with 8 tasks blinking 8 leds and use logic analyzer to see results.
-
- Posts: 73
- Joined: Mon Mar 09, 2020 7:36 pm
Re: application for alarm project collect data
All of your requirements are not clear. I think I would design this as two tasks, one to collect information from all sensors at the rate that works best. The second task would be reporting, so send every report period unless change greater than trigger_level happened since last report. You should manage semaphores between the collection for sensor(A) and evaluating or reporting Sensor(A).
You can have mailboxes that contain a new reading and the reporter reads the mail. You could have interrupts if the new reading is more than trigger_level different than last reported. Questions like that get into what your real requirements are. an interrupt to say report Sensor(C) which is now above trigger_level difference, might well be interrupting the scheduled report of Sensor(C) and the last reported value has not made it back to the measuring side so it sets an interrupt.
If reporter is scanning last measurements twice as fast as the measuring task, and you are not dealing with a time critical issue, You should be able to have a relatively simple reporter.
You can have mailboxes that contain a new reading and the reporter reads the mail. You could have interrupts if the new reading is more than trigger_level different than last reported. Questions like that get into what your real requirements are. an interrupt to say report Sensor(C) which is now above trigger_level difference, might well be interrupting the scheduled report of Sensor(C) and the last reported value has not made it back to the measuring side so it sets an interrupt.
If reporter is scanning last measurements twice as fast as the measuring task, and you are not dealing with a time critical issue, You should be able to have a relatively simple reporter.
Re: application for alarm project collect data
in my application i have 4 sensor (maybe i will add another type ) (bme280,bh1750,mcp3428,and pcf8574 ) using (UncleRus/esp-idf-lib) and the customer can plugin what he want in 8 socket (same type or different type) and my code can adapt automatic with device connecting and initialize and start read those device detected (if one or more are Unplug the code send error in topic and stop to read )
Who is online
Users browsing this forum: No registered users and 100 guests