avaldebe / PMserial

Arduino library for PM sensors with serial interface
MIT License
53 stars 21 forks source link

Improving the binding to the `Serial` object and fix SoftwareSerial bug #20

Closed heX16 closed 3 years ago

heX16 commented 3 years ago

Consider the following situations:

  1. We use another MCU (not known to this library) where the set of parameters for Serial.init(...) is different (this situation already happened with ESP32).
  2. We use our own implementation of Serial inherited from Stream (such as AltSoftSerial).
  3. Pin numbers in Serial can change on the fly (cofigure via web interface).
  4. We have a dust sensor and another sensor (of another type) connected to the same SoftwareSerial, but responding to a different query format. This configuration is valid, and saving pins - is a common phenomenon. (similar to the situation in #5)
  5. We have 16 sensors that need to be polled. For example these are compressed air lines in industry.

In the current implementation of the library it is problematic to solve these problems (without modifying the library code). So I decided to expand PR and add more general mechanisms.

In normal projects, the problem of creating objects is solved through the "factory" pattern, but for MK this is superfluous.

It will take some more time to develop (more examples need to be written) and hopefully everyone will like the result.


Russian: Рассмотрим следующие ситуации:

  1. Мы используем другой МК (не известный этой библиотеке), в котором набор параметров для Serial.init(...) отличается (такая ситуация уже произошла с ESP32).
  2. Мы используем свою собственную реализацию Serial унаследованную от Stream (например AltSoftSerial)..
  3. Номера пин у SoftwareSerial изменяются на лету (кофигурация через web-интерфейс).
  4. У нас датчик пыли и еще один датчик (другого типа) подключенный к этому же SoftwareSerial, но отвечающий на другой формат запроса. Такая конфигурация валидна, и экономия пинов это обычное явление. (похоже на ситуацию в #5)
  5. У нас 16 датчиков которые нужно опрашивать. Например это линии сжатого воздуха в промышленности.

В текущей реализации библиотеки решить эти проблемы (без внесения изменений в код библиотеки) проблематично. Поэтому я решил расширить PR и добавить более общие механизмы.

В обычных проектах проблему создания объектов решают через патерн "фабрика", но для МК это излишне.

Разработка займет еще некоторое время (нужно написать дополнительные примеры) и надеюсь результат понравится всем.

Changes

Core:

SoftwareSerial bug - https://github.com/avaldebe/PMserial/issues/19 Improving the binding to the Serial object

heX16 commented 3 years ago

image

heX16 commented 3 years ago

Working: https://www.instagram.com/p/CL91-rrHANP/

(i use two SoftwareSerial - for CO2 sensor and PM5003 sensor.

avaldebe commented 3 years ago

Looks like the platformio travis integration now uses Python 3.7, it was 2.7 when I set it up.

In any case, I updated .travis.yml (a0e326e) which fix most of the builds. The examples/OLED_64x48 is still crashing, looks like the ESP8266_SSD1306 library is no longer available.

avaldebe commented 3 years ago

The examples/OLED_64x48 is still crashing, looks like the ESP8266_SSD1306 library is no longer available.

The ESP8266_SSD1306 library changed name to ESP8266 and ESP32 OLED driver for SSD1306 displays

avaldebe commented 3 years ago

The ESP8266_SSD1306 library changed name to ESP8266 and ESP32 OLED driver for SSD1306 displays

Fixed on 5e9de28. Please update your branch, so the builds succeed

heX16 commented 3 years ago

Work in progress... (see topic)

avaldebe commented 3 years ago

Thanks for this PR. I learned something the Atmel AVR C++ compiler and the code got better.

Thanks again, Á.