diff --git a/libraries/AD5144A/AD5144A.cpp b/libraries/AD5144A/AD5144A.cpp index 1e58b46d..65a13468 100644 --- a/libraries/AD5144A/AD5144A.cpp +++ b/libraries/AD5144A/AD5144A.cpp @@ -370,19 +370,25 @@ uint8_t AD51XX::readBack(const uint8_t rdac, const uint8_t mask) { // COMMAND 3 - page 20 _wire->beginTransmission(_address); - int a = _wire->write(0x30 | rdac); + _wire->write(0x30 | rdac); + _wire->write(mask); + _wire->endTransmission(); + _wire->requestFrom(_address, (uint8_t)1); + return _wire->read(); + + // int a = _wire->write(0x30 | rdac); // Serial.print("READBACK cmd: "); // Serial.print(a); - a = _wire->write(mask); + // a = _wire->write(mask); // Serial.print(" val: "); // Serial.print(a); - a = _wire->endTransmission(); + // a = _wire->endTransmission(); // Serial.print(" TX: "); // Serial.println(a); - a = _wire->requestFrom(_address, (uint8_t)1); + // a = _wire->requestFrom(_address, (uint8_t)1); // Serial.print(" RF: "); // Serial.println(a); - return _wire->read(); + // return _wire->read(); } diff --git a/libraries/DEVRANDOM/examples/DEVRANDOM_demo/DEVRANDOM_demo.ino b/libraries/DEVRANDOM/examples/DEVRANDOM_demo/DEVRANDOM_demo.ino index 5d07fde8..fdfa69a1 100644 --- a/libraries/DEVRANDOM/examples/DEVRANDOM_demo/DEVRANDOM_demo.ino +++ b/libraries/DEVRANDOM/examples/DEVRANDOM_demo/DEVRANDOM_demo.ino @@ -93,15 +93,15 @@ void setup() Serial.println(); delay(1000); - uint32_t x; - fscanf((FILE*)&dr, "%lu", &x); - Serial.print("UINT32: "); - Serial.println(x, HEX); + // uint32_t x; + // fscanf((FILE*)&dr, "%lu", &x); // fails on ESP32 + // Serial.print("UINT32: "); + // Serial.println(x, HEX); - uint16_t y; - fscanf((FILE*)&dr, "%u", &y); - Serial.print("UINT16: "); - Serial.println(y, HEX); + // uint16_t y; + // fscanf((FILE*)&dr, "%u", &y); // fails on ESP32 + // Serial.print("UINT16: "); + // Serial.println(y, HEX); // float f; // fscanf((FILE*)&dr, "%e", &f); // does not work on UNO. diff --git a/libraries/DHTstable/examples/dht11_two/dht11_two.ino b/libraries/DHTstable/examples/dht11_two/dht11_two.ino index a0246274..4c3ea31d 100644 --- a/libraries/DHTstable/examples/dht11_two/dht11_two.ino +++ b/libraries/DHTstable/examples/dht11_two/dht11_two.ino @@ -29,14 +29,14 @@ void setup() void loop() { Serial.print("DHT A:\t"); - int chk = DHT_A.read11(DHT11_PIN_A); + DHT_A.read11(DHT11_PIN_A); Serial.print(DHT_A.getHumidity()); Serial.print(",\t"); Serial.println(DHT_A.getTemperature()); Serial.print("DHT B:\t"); - chk = DHT_B.read11(DHT11_PIN_B); + DHT_B.read11(DHT11_PIN_B); Serial.print(DHT_B.getHumidity()); Serial.print(",\t"); Serial.println(DHT_B.getTemperature()); diff --git a/libraries/FastTrig/examples/fastTrig_optimize/fastTrig_optimize.ino b/libraries/FastTrig/examples/fastTrig_optimize/fastTrig_optimize.ino index 34d546c0..9083c52f 100644 --- a/libraries/FastTrig/examples/fastTrig_optimize/fastTrig_optimize.ino +++ b/libraries/FastTrig/examples/fastTrig_optimize/fastTrig_optimize.ino @@ -69,7 +69,7 @@ int optimize() flag = true; } } - // if (flag) Serial.print('*'); // uncomment this as you want to spot the changes. + if (flag) Serial.print('*'); // comment if you do not want see changes. isinTable16[i] = t + idx; Serial.print(isinTable16[i]); Serial.print(", "); diff --git a/libraries/FastTrig/examples/fastTrig_test1/fastTrig_test1.ino b/libraries/FastTrig/examples/fastTrig_test1/fastTrig_test1.ino index 972ad196..5faa3e61 100644 --- a/libraries/FastTrig/examples/fastTrig_test1/fastTrig_test1.ino +++ b/libraries/FastTrig/examples/fastTrig_test1/fastTrig_test1.ino @@ -47,8 +47,9 @@ bool test_hw_support() // to be elaborated d2 = micros() - start; Serial.println(d1); Serial.println(d2); + Serial.println(y); // keep compiler happy Serial.println(); - return (d1 / d2) < 1.5; // just a guess for now. + return (d1 / d2) < 1.5; // just a guess for now. } diff --git a/libraries/FunctionGenerator/examples/functionGeneratorPlotter/functionGeneratorPlotter.ino b/libraries/FunctionGenerator/examples/functionGeneratorPlotter/functionGeneratorPlotter.ino index 1c18296b..4c2bfd8c 100644 --- a/libraries/FunctionGenerator/examples/functionGeneratorPlotter/functionGeneratorPlotter.ino +++ b/libraries/FunctionGenerator/examples/functionGeneratorPlotter/functionGeneratorPlotter.ino @@ -5,7 +5,7 @@ // DATE: 2020-06-10 // URL: https://github.com/RobTillaart/FunctionGenerator // -// use a Serial plotter to show the data +// use a Serial plotter to show the data #include "functionGenerator.h" @@ -16,8 +16,8 @@ funcgen gen; void setup() { Serial.begin(115200); - // Serial.print("Start functionGeneratorPerformance - LIB VERSION: "); - // Serial.println(FUNCTIONGENERATOR_LIB_VERSION); + // Serial.print("Start functionGeneratorPerformance - LIB VERSION: "); + // Serial.println(FUNCTIONGENERATOR_LIB_VERSION); gen.setAmplitude(50); gen.setFrequency(1); @@ -28,24 +28,24 @@ void loop() { float t = millis() * 0.001; - // UNCOMMENT WAVES YOU WANT TO SEE - // DO NOT FORGET THE '\t' SEPARATOR PRINT + // UNCOMMENT WAVES YOU WANT TO SEE + // DO NOT FORGET THE '\t' SEPARATOR PRINT // Serial.print(t, 3); // Serial.print("\t"); // Serial.print(gen.square(t)); // Serial.print("\t"); -// Serial.print(gen.sawtooth(t, 0)); // up /| +// Serial.print(gen.sawtooth(t, 0)); // up /| signal // Serial.print("\t"); -// Serial.print(gen.sawtooth(t, 1)); // down |\ +// Serial.print(gen.sawtooth(t, 1)); // down |\ signal // Serial.print("\t"); // Serial.print(gen.triangle(t)); // Serial.print("\t"); // Serial.print(gen.sinus(t)); // Serial.print("\t"); - Serial.print(gen.stair(t, 16, 0)); // step up + Serial.print(gen.stair(t, 16, 0)); // step up Serial.print("\t"); - Serial.print(gen.stair(t, 16, 1)); // step down + Serial.print(gen.stair(t, 16, 1)); // step down Serial.print("\t"); // Serial.print(gen.random()); // Serial.print("\t"); diff --git a/libraries/I2C_24LC1025/examples/24LC1025_test/24LC1025_test.ino b/libraries/I2C_24LC1025/examples/24LC1025_test/24LC1025_test.ino index cd8433c2..83ceca15 100644 --- a/libraries/I2C_24LC1025/examples/24LC1025_test/24LC1025_test.ino +++ b/libraries/I2C_24LC1025/examples/24LC1025_test/24LC1025_test.ino @@ -59,10 +59,14 @@ void dump(uint32_t from, uint32_t to) { char buffer[24]; Serial.print('\n'); - sprintf(buffer, "%08lX\t", i); +#if defined (ESP8266) || defined(ESP32) + sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int) +#else + sprintf(buffer, "%08lX\t", i); // AVR needs lX +#endif Serial.print(buffer); } - sprintf(buffer, "%02X\t", ee.readByte(i)); + sprintf(buffer, "%02X\t", x); Serial.print(buffer); } Serial.println(); diff --git a/libraries/I2C_24LC1025/examples/24LC1025_test_read/24LC1025_test_read.ino b/libraries/I2C_24LC1025/examples/24LC1025_test_read/24LC1025_test_read.ino index 926117e2..799dfb42 100644 --- a/libraries/I2C_24LC1025/examples/24LC1025_test_read/24LC1025_test_read.ino +++ b/libraries/I2C_24LC1025/examples/24LC1025_test_read/24LC1025_test_read.ino @@ -123,8 +123,11 @@ void dump(uint32_t from, uint32_t to) { char buffer[24]; Serial.print('\n'); - // sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int) - sprintf(buffer, "%08lX\t", i); // AVR needs lX +#if defined (ESP8266) || defined(ESP32) + sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int) +#else + sprintf(buffer, "%08lX\t", i); // AVR needs lX +#endif Serial.print(buffer); } sprintf(buffer, "%02X\t", ee.readByte(i)); diff --git a/libraries/I2C_EEPROM/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino b/libraries/I2C_EEPROM/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino index 7d64dee1..8426b5ed 100644 --- a/libraries/I2C_EEPROM/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino +++ b/libraries/I2C_EEPROM/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino @@ -129,7 +129,11 @@ void dump(uint32_t from, uint32_t to) { char buffer[24]; Serial.print('\n'); - sprintf(buffer, "%08lX\t", i); +#if defined (ESP8266) || defined(ESP32) + sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int) +#else + sprintf(buffer, "%08lX\t", i); // AVR needs lX +#endif; Serial.print(buffer); } sprintf(buffer, "%02X\t", ee.readByte(i)); diff --git a/libraries/I2C_EEPROM/readme.md b/libraries/I2C_EEPROM/readme.md index e8c25a65..8a50d843 100644 --- a/libraries/I2C_EEPROM/readme.md +++ b/libraries/I2C_EEPROM/readme.md @@ -20,6 +20,21 @@ MicroChip 24LC512, 24LC256, 24LC64, 24LC32, 24LC16, 24LC08, 24LC04, 24LC02, 24LC The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md) +## Schematic + +```cpp + +---U---+ + A0 | 1 8 | VCC = +5V + A1 | 2 7 | WP = write protect pin + A2 | 3 6 | SCL = I2C clock + GND | 4 5 | SDA = I2C data + +-------+ + +default address = 0x50 .. 0x57 depending on three address lines + +``` + + ## Interface The interface is kept quite identical to the I2C_24LC1025 library. diff --git a/libraries/IEEE754tools/IEEE754tools.h b/libraries/IEEE754tools/IEEE754tools.h index 189deac3..918a26bc 100644 --- a/libraries/IEEE754tools/IEEE754tools.h +++ b/libraries/IEEE754tools/IEEE754tools.h @@ -25,11 +25,11 @@ #define IEEE754_VERSION (F("0.2.3")) -// (un)comment lines to configure functionality / size +// (un)comment lines to configure functionality / size //#define IEEE754_ENABLE_MSB // +78 bytes -// IEEE754 float layout; +// IEEE754 float layout; struct IEEEfloat { uint32_t m:23; @@ -38,7 +38,7 @@ struct IEEEfloat }; -// IEEE754 double layout; +// IEEE754 double layout; struct IEEEdouble { uint64_t m:52; @@ -47,9 +47,9 @@ struct IEEEdouble }; -// Arduino UNO double layout: -// the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse -// a filler is added for the remaining bits. These might be useful in future? +// Arduino UNO double layout: +// the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse +// a filler is added for the remaining bits. These might be useful in future? struct _DBL { uint32_t filler:29; @@ -59,7 +59,7 @@ struct _DBL }; -// for packing and unpacking a float +// for packing and unpacking a float union _FLOATCONV { IEEEfloat p; @@ -68,7 +68,7 @@ union _FLOATCONV }; -// for packing and unpacking a double +// for packing and unpacking a double union _DBLCONV { // IEEEdouble p; @@ -79,9 +79,9 @@ union _DBLCONV // -// DEBUG FUNCTIONS +// DEBUG FUNCTIONS // -// print float components +// print float components void dumpFloat(float number) { IEEEfloat* x = (IEEEfloat*) ((void*)&number); @@ -91,13 +91,13 @@ void dumpFloat(float number) Serial.print("\t"); Serial.println(x->m, HEX); - // Serial.print(" sign: "); Serial.print(x->s); - // Serial.print(" exp: "); Serial.print(x->e); - // Serial.print(" mant: "); Serial.println(x->m); + // Serial.print(" sign: "); Serial.print(x->s); + // Serial.print(" exp: "); Serial.print(x->e); + // Serial.print(" mant: "); Serial.println(x->m); } -// print "double" components +// print "double" components void dumpDBL(struct _DBL dbl) { Serial.print(dbl.s, HEX); @@ -109,20 +109,24 @@ void dumpDBL(struct _DBL dbl) // -// mapping to/from 64bit double - best effort +// mapping to/from 64bit double - best effort // -// converts a float to a packed array of 8 bytes representing a 64 bit double -// restriction exponent and mantissa. -// float; array of 8 bytes; LSBFIRST; MSBFIRST +// converts a float to a packed array of 8 bytes representing a 64 bit double +// restriction exponent and mantissa. +// float; array of 8 bytes; LSBFIRST; MSBFIRST void float2DoublePacked(float number, byte* bar, int byteOrder = LSBFIRST) { _FLOATCONV fl; + // prevent warning/error on ESP build + fl.p.s = 0; + fl.p.e = 0; + fl.p.m = 0; fl.f = number; _DBLCONV dbl; dbl.p.filler = 0; dbl.p.s = fl.p.s; - dbl.p.e = fl.p.e - 127 + 1023; // exponent adjust + dbl.p.e = fl.p.e - 127 + 1023; // exponent adjust dbl.p.m = fl.p.m; #ifdef IEEE754_ENABLE_MSB @@ -146,9 +150,9 @@ void float2DoublePacked(float number, byte* bar, int byteOrder = LSBFIRST) } -// converts a packed array of bytes into a 32bit float. -// there can be an exponent overflow -// the mantissa is truncated to 23 bits. +// converts a packed array of bytes into a 32bit float. +// there can be an exponent overflow +// the mantissa is truncated to 23 bits. float doublePacked2Float(byte* bar, int byteOrder = LSBFIRST) { _FLOATCONV fl; @@ -188,10 +192,10 @@ float doublePacked2Float(byte* bar, int byteOrder = LSBFIRST) // -// TEST FUNCTIONS +// TEST FUNCTIONS // -// ~1.7x faster +// ~1.7x faster int IEEE_NAN(float number) { uint16_t* x = ((uint16_t*) &number + 1); @@ -199,7 +203,7 @@ int IEEE_NAN(float number) } -// ~3.4x faster +// ~3.4x faster int IEEE_INF(float number) { uint8_t* x = ((uint8_t*) &number); @@ -210,7 +214,7 @@ int IEEE_INF(float number) } -// for the real speed freaks, the next +// for the real speed freaks, the next boolean IEEE_PosINF(float number) { return (* ((uint16_t*) &number + 1) ) == 0x7F80; @@ -223,7 +227,7 @@ boolean IEEE_NegINF(float number) // -// PROPERTIES +// PROPERTIES // uint8_t IEEE_Sign(float number) { @@ -245,11 +249,11 @@ uint32_t IEEE_Mantisse(float number) // -// MATH FUNCTIONS +// MATH FUNCTIONS // -// f = f * 2^n -// factor ~2.7; (tested with *16) more correct than the faster one +// f = f * 2^n +// factor ~2.7; (tested with *16) more correct than the faster one float IEEE_POW2(float number, int n) { _FLOATCONV fl; @@ -264,7 +268,7 @@ float IEEE_POW2(float number, int n) } -// WARNING no overflow detection in the SHIFT (factor ~3.5) +// WARNING no overflow detection in the SHIFT (factor ~3.5) float IEEE_POW2fast(float number, int n) { _FLOATCONV fl; @@ -274,7 +278,7 @@ float IEEE_POW2fast(float number, int n) } -// - FAILS ON ESP32 (x16 => x256 strange) +// - FAILS ON ESP32 (x16 => x256 strange) float IEEE_FLOAT_POW2fast(float number, int n) { IEEEfloat* x = (IEEEfloat*) ((void*)&number); @@ -283,8 +287,8 @@ float IEEE_FLOAT_POW2fast(float number, int n) } -// - NOT FASTER -// - FAILS ON ESP32 (==> divides by 4) +// - NOT FASTER +// - FAILS ON ESP32 (==> divides by 4) float IEEE_FLOAT_DIV2(float number) { IEEEfloat* x = (IEEEfloat*) ((void*)&number); @@ -314,11 +318,11 @@ bool IEEE_FLOAT_NEQ(float &f, float &g) //////////////////////////////////////////////////////////////////////////////// // -// NOT TESTED FUNCTIONS +// NOT TESTED FUNCTIONS // // -// get truncated part as separate float. +// get truncated part as separate float. // void doublePacked2Float2(byte* bar, int byteOrder, float* value, float* error) { @@ -363,7 +367,7 @@ void doublePacked2Float2(byte* bar, int byteOrder, float* value, float* error) } -// what is this??? +// what is this??? float IEEE_FLIP(float number) { _FLOATCONV fl; diff --git a/libraries/LTC2991/LTC2991.cpp b/libraries/LTC2991/LTC2991.cpp index 0d5aa214..2313a274 100644 --- a/libraries/LTC2991/LTC2991.cpp +++ b/libraries/LTC2991/LTC2991.cpp @@ -544,7 +544,7 @@ uint16_t LTC2991::_readRegister16(const uint8_t reg) { uint16_t x = _readRegister(reg) << 8; x |= _readRegister(reg + 1); - bool dataValid = (x & 0x8000) > 0; // do nothing for now... + // bool dataValid = (x & 0x8000) > 0; // TODO error handling x &= 0x7FFF; return x; } diff --git a/libraries/LTC2991/README.md b/libraries/LTC2991/README.md index f33ab0b2..1d50c1e8 100644 --- a/libraries/LTC2991/README.md +++ b/libraries/LTC2991/README.md @@ -133,6 +133,7 @@ See examples.. - get hardware to - test test test - update documentation +- error handling #### could diff --git a/libraries/M62429/examples/M62429_RAW_performance/M62429_RAW_performance.ino b/libraries/M62429/examples/M62429_RAW_performance/M62429_RAW_performance.ino index 0883eeb5..580770d8 100644 --- a/libraries/M62429/examples/M62429_RAW_performance/M62429_RAW_performance.ino +++ b/libraries/M62429/examples/M62429_RAW_performance/M62429_RAW_performance.ino @@ -55,6 +55,9 @@ void setup() stop = micros(); Serial.print("getAttn: \t"); Serial.println(stop - start); + Serial.print("getAttn: \t"); + Serial.println(x); // keep build CI compiler happy + delay(100); Serial.println("\nDone..."); diff --git a/libraries/M62429/examples/M62429_performance/M62429_performance.ino b/libraries/M62429/examples/M62429_performance/M62429_performance.ino index aec74dfb..36c9f1dd 100644 --- a/libraries/M62429/examples/M62429_performance/M62429_performance.ino +++ b/libraries/M62429/examples/M62429_performance/M62429_performance.ino @@ -56,6 +56,8 @@ void setup() stop = micros(); Serial.print("getVolume: \t"); Serial.println(stop - start); + Serial.print("getVolume: \t"); + Serial.println(x); // keep build-CI compiler happy delay(100); AMP.setVolume(2, 0); diff --git a/libraries/MAX6675/examples/MAX6675_test_plotter/MAX6675_test_plotter.ino b/libraries/MAX6675/examples/MAX6675_test_plotter/MAX6675_test_plotter.ino index 87b7d3d4..c626a7a7 100644 --- a/libraries/MAX6675/examples/MAX6675_test_plotter/MAX6675_test_plotter.ino +++ b/libraries/MAX6675/examples/MAX6675_test_plotter/MAX6675_test_plotter.ino @@ -34,6 +34,7 @@ void setup() thermoCouple.setOffset(273); int status = thermoCouple.read(); + if (status != 0) Serial.println(status); temp = thermoCouple.getTemperature(); } diff --git a/libraries/PCF8574/examples/PCF8574_performance/PCF8574_performance.ino b/libraries/PCF8574/examples/PCF8574_performance/PCF8574_performance.ino index 83e02236..12c43210 100644 --- a/libraries/PCF8574/examples/PCF8574_performance/PCF8574_performance.ino +++ b/libraries/PCF8574/examples/PCF8574_performance/PCF8574_performance.ino @@ -30,7 +30,9 @@ void setup() int x = PCF.read8(); stop = micros(); Serial.print("Read:\t"); - Serial.println(stop - start); + Serial.print(stop - start); + Serial.print("\t"); + Serial.println(x); // keep build CI compiler happy delay(1000); start = micros(); diff --git a/libraries/PCF8591/README.md b/libraries/PCF8591/README.md index 18a8813d..9f9475d4 100644 --- a/libraries/PCF8591/README.md +++ b/libraries/PCF8591/README.md @@ -13,8 +13,9 @@ Arduino Library for PCF8591 I2C 4 channel 8 bit ADC + 1 channel 8 bit DAC. ## Description -**warning** during tests I could overclock the chip up to 650 KHz but it is only specified -to run at 100 kHz. After getting pretty hot it broke down. +**warning** during tests I could overclock the PCF8591 chip up to 650 KHz. +However it is only specified to run at 100 kHz. +After some time it was getting pretty hot and it broke down. So overclocking is fun but not recommended. PCF8591 has one 8 bit ADC on board for 4 channels. The ADC is 8 bit and quite fast. @@ -44,7 +45,7 @@ Also set initial value for the DAC. Returns **true** if successful. ### ADC part -The PCF8591 has four 8 bit ADC channels. Values = 0..255 +The PCF8591 has four 8 bit ADC channels. Values = 0..255. - **void enableINCR()** used in analogRead4(); Could become private in the future. - **void disableINCR()** idem. @@ -62,12 +63,13 @@ This cache is filled both by **analogRead()** and **analogRead4()**. See example ### DAC part -The PCF8591 has one 8 bit DAC. output value 0..255 == 0..Vref Volts (datasheet) +The PCF8591 has one 8 bit DAC. output value 0..255 == 0..Vref Volts (datasheet). - **void enableDAC()** switch on the analogue output. - **void disableDAC()** switch off the analogue output (high impedance) Sort of energy saving mode. - **bool isDACEnabled()** check the modus operandi. - **bool analogWrite(uint8_t value = 0)** writes a value 0..255 to the DAC. Check datasheet for voltage. +Note, this is a real voltage not a PWM signal like **analogWrite()** on an UNO. - **uint8_t lastWrite()** get last written value from cache. - **int lastError()** always check this value after a read / write to see if it was OK (== 0). After the read the error value is reset to OK. diff --git a/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino b/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino index 9e01c728..8d3c15a9 100644 --- a/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino +++ b/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino @@ -116,6 +116,7 @@ void test_ADC() stop = micros(); Serial.print(" | "); Serial.print((stop - start) * 0.001); + if (x == 255) return; // keep build CI happy } @@ -146,6 +147,7 @@ void test_ADC_error() } Serial.print(" | "); Serial.print(perc); + if (x == 255) return; // keep build CI happy } diff --git a/libraries/RS485/README.md b/libraries/RS485/README.md index d718a7cf..c06eb76b 100644 --- a/libraries/RS485/README.md +++ b/libraries/RS485/README.md @@ -46,14 +46,20 @@ This is the default behaviour of every RS485 device. #### Stream interface +The most important commands of the Stream interface are: + - **int available()** returns the number of characters available in the buffer. - **int read()** read a character from the RS485 stream. - **int peek()** peeks a character ahead. (less used). - **void flush()** flush the stream. (less used). +- https://www.arduino.cc/reference/en/language/functions/communication/stream/ All variations of **print()**, **println()** and **write()** can be used, the library calculates the time needed to set the RS485 chip in transmit mode. +An important command from the stream interface is the **setTimeOut()** as +this allows reads on the RS485 bus that are limited + ## Operation @@ -61,9 +67,26 @@ A RS485 controlled device is typically waiting for a command or message and is therefore default in listening or receiving mode. Only when the device needs to answer the library will automatically set the RS485 chip in sending mode, wait for enough time to "flush the buffer" and -resumes with listening. +resumes with listening. -- see examples (TODO). + +#### Pull up resistors + +Do not forget to use one pull up (A line) and one pull down (B line) +at only one end of the bus. +Values depend on the length of the cables, start with 1 KΩ. + + +#### Wires + +Preferred wire for RS485 is STP (Shielded Twisted Pair), however +UTP (Unshielded) will works in many cases. +Typical for most applications CAT5 (100 Mbit) will do the job. + +Note CAT5 has 4 x 2 twisted wires so there are 6 cables to spare. +These could be used e.g. to build a FULL DUPLEX version in which +every slave has 2 RS485 ports, one for receiving and one for sending. +Another application is to use these as power lines e.g 5 and 12 V. #### yield() diff --git a/libraries/RS485/RS485.cpp b/libraries/RS485/RS485.cpp index 577e405e..9d111fdf 100644 --- a/libraries/RS485/RS485.cpp +++ b/libraries/RS485/RS485.cpp @@ -25,7 +25,7 @@ RS485::RS485(Stream * stream, uint8_t sendPin, uint8_t deviceID) _stream = stream; _sendPin = sendPin; _deviceID = deviceID; - + pinMode(_sendPin, OUTPUT); setRXmode(); // receiver mode } @@ -69,7 +69,7 @@ size_t RS485::write(char * array, uint8_t length) /////////////////////////////////////////////////////// // -// discussion about write and yield see +// discussion about write and yield see // - https://github.com/RobTillaart/RS485/issues/2 // @@ -89,9 +89,9 @@ size_t RS485::write(uint8_t * array, uint8_t length) return n; } -#else +#else -// 0.2.1 version +// 0.2.1 version // no yield() calls - might be blocking... size_t RS485::write(uint8_t * array, uint8_t length) { diff --git a/libraries/RS485/examples/RS485_simple_master/RS485_simple_master.ino b/libraries/RS485/examples/RS485_simple_master/RS485_simple_master.ino index b6e6ddb3..08c843c0 100644 --- a/libraries/RS485/examples/RS485_simple_master/RS485_simple_master.ino +++ b/libraries/RS485/examples/RS485_simple_master/RS485_simple_master.ino @@ -33,6 +33,7 @@ void loop() if (rs485.available() > 0) { int status = rs485.read(); + Serial.println(status); } } diff --git a/libraries/RunningMedian/README.md b/libraries/RunningMedian/README.md index 1333f29e..f2ca1a05 100644 --- a/libraries/RunningMedian/README.md +++ b/libraries/RunningMedian/README.md @@ -71,7 +71,7 @@ There are several options that can be configured via defines at compile time, th ### Base functions - **clear()** resets internal buffer and variables, effectively empty the buffer. -- **add(const float value) ** adds a new value to internal buffer, +- **add(const float value)** adds a new value to internal buffer, optionally replacing the oldest element if the buffer is full - **float getMedian()** returns the median == middle element - **float getAverage()** returns average of **all** the values in the internal buffer diff --git a/libraries/RunningMedian/examples/RunningMedian_large/RunningMedian_large.ino b/libraries/RunningMedian/examples/RunningMedian_large/RunningMedian_large.ino index 8f90a833..921911e0 100644 --- a/libraries/RunningMedian/examples/RunningMedian_large/RunningMedian_large.ino +++ b/libraries/RunningMedian/examples/RunningMedian_large/RunningMedian_large.ino @@ -49,6 +49,8 @@ void loop() Serial.print('\t'); Serial.print(dur3); Serial.print('\t'); + Serial.print(value); + Serial.print('\t'); Serial.println(); } diff --git a/libraries/Stopwatch_RT/examples/stopwatch_demo/stopwatch_demo.ino b/libraries/Stopwatch_RT/examples/stopwatch_demo/stopwatch_demo.ino new file mode 100644 index 00000000..f0e32d1e --- /dev/null +++ b/libraries/Stopwatch_RT/examples/stopwatch_demo/stopwatch_demo.ino @@ -0,0 +1,65 @@ +// +// FILE: stopwatch_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: sample demo stopwatch class +// DATE: 2022-09-08 +// URL: https://github.com/RobTillaart/StopWatch_RT + + +#include + +StopWatch myStopwatch; + +// configure to your needs +#define RUNPIN 13 +#define STARTPIN 7 +#define STOPPIN 6 +#define RESETPIN 5 + +uint32_t lastDisplay = 0; +uint32_t lastTimeDisplayed = -1; + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print("STOPWATCH_LIB_VERSION: "); + Serial.println(STOPWATCH_LIB_VERSION); + + pinMode(RUNPIN, OUTPUT); // indicator stopwatch is running + digitalWrite(RUNPIN, LOW); + pinMode(STARTPIN, INPUT_PULLUP); + pinMode(STOPPIN, INPUT_PULLUP); + pinMode(RESETPIN, INPUT_PULLUP); +} + + +void loop() +{ + // HANDLE IO PINS + if (digitalRead(STARTPIN) == LOW) myStopwatch.start(); + if (digitalRead(STOPPIN) == LOW) myStopwatch.stop(); + if (digitalRead(RESETPIN) == LOW) myStopwatch.reset(); + + // HANDLE RUNNINGLED + digitalWrite(RUNPIN, myStopwatch.isRunning()); + + // HANDLE DISPLAY + if (millis() - lastDisplay > 100) + { + lastDisplay = millis(); + uint32_t ti = myStopwatch.elapsed(); + if (ti != lastTimeDisplayed) + { + lastTimeDisplayed = ti; + Serial.print("TIME: "); + Serial.println(ti); + } + } + + // do other stuff here +} + + +// -- END OF FILE -- diff --git a/libraries/printHelpers/examples/print_sci/print_sci.ino b/libraries/printHelpers/examples/print_sci/print_sci.ino index 2aec14d4..ea96215b 100644 --- a/libraries/printHelpers/examples/print_sci/print_sci.ino +++ b/libraries/printHelpers/examples/print_sci/print_sci.ino @@ -14,7 +14,7 @@ void setup() Serial.println(sizeof(float)); Serial.println(sizeof(double)); - char buffer[200]; + double c = 2.99792458E8; // speed of light; double m = 7.34767309E20; // mass of moon double E = m * c * c; @@ -27,7 +27,9 @@ void setup() Serial.println(E, 4); Serial.println("Cannot handle floats / doubles > MAXLONG\n"); + #if defined(ARDUINO_ARCH_AVR) + char buffer[200]; Serial.print("dtostrf print:\t"); Serial.println(dtostrf(E, 4, 4, buffer)); Serial.println("Has no scientific notation\n"); @@ -39,18 +41,21 @@ void setup() Serial.println("Limited to 7 decimals\n"); #endif + Serial.print(" sci print:\t"); Serial.println(sci(E, 4)); Serial.print(" sci print:\t"); Serial.println(sci(E, 16)); Serial.println("limited only by precision float\n"); + Serial.print(" eng print:\t"); Serial.println(eng(E, 4)); Serial.print(" eng print:\t"); Serial.println(eng(E, 16)); Serial.println("limited only by precision float\n"); + E /= 100; // more interesting effect Serial.println("scieng() is not meant to use directly"); Serial.println("it works well up exponent multiple of 1..9"); @@ -62,6 +67,7 @@ void setup() Serial.println(scieng(E, 8, em)); } + Serial.println("\ndone..."); }