stoduk / PingSerial

Arduino library for using serial enabled ultrasonic distance modules (eg. US-100)
MIT License
16 stars 10 forks source link

Cant compile for nodemcu/ESP8266 #6

Open rajil opened 6 years ago

rajil commented 6 years ago

I tried to compile the example for a nodemcu, and got a bunch of errors. Any idea what is the issue?

Build options changed, rebuilding all
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp: In member function 'byte PingSerial::data_available()':
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: error: no matching function for call to 'max(long unsigned int, uint16_t&)'
                 _max_op_duration_ms = max(millis() - _op_started, _max_op_duration_ms);
                                                                                      ^
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: note: candidates are:
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
                 _max_op_duration_ms = max(millis() - _op_started, _max_op_duration_ms);
                                                                                      ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
                 _max_op_duration_ms = max(millis() - _op_started, _max_op_duration_ms);
                                                                                      ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'uint16_t {aka short unsigned int}')
                 _max_op_duration_ms = max(millis() - _op_started, _max_op_duration_ms);
                                                                                      ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:162:86: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'uint16_t {aka short unsigned int}')
                 _max_op_duration_ms = max(millis() - _op_started, _max_op_duration_ms);
                                                                                      ^
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: error: no matching function for call to 'max(uint16_t&, int)'
         _timeout_count = max(_timeout_count, 1); 
                                               ^
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: note: candidates are:
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short unsigned int'
         _timeout_count = max(_timeout_count, 1); 
                                               ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short unsigned int'
         _timeout_count = max(_timeout_count, 1); 
                                               ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: note:   deduced conflicting types for parameter 'const _Tp' ('short unsigned int' and 'int')
         _timeout_count = max(_timeout_count, 1); 
                                               ^
In file included from /home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/user/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266/Arduino.h:254,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.h:17,
                 from /home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note:   template argument deduction/substitution failed:
/home/user/Arduino/libraries/PingSerial-master/PingSerial.cpp:195:47: note:   deduced conflicting types for parameter 'const _Tp' ('short unsigned int' and 'int')
         _timeout_count = max(_timeout_count, 1); 
                                               ^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
rajil commented 6 years ago

The ESP8266 library is version 2.4.1.

stoduk commented 6 years ago

https://github.com/kitesurfer1404/WS2812FX/issues/58

Looks to be this issue - nodemcu v. 2.4.0 replaced the macros (which admittedly have problems if people do daft things, eg. calling max(foo++, bar++)) with functions std::min and std::max which barf if the two arguments are not the same type.

Can you try these two fixes:

rajil commented 6 years ago

Thanks, with these changes the code compiles. However, I dont see data being read from the nodemcu v3. What pins on nodemcuv3 should i connect the Trigger and Echo pins?

stoduk commented 6 years ago

I've never used this with nodemcu boards, only Arduino/Atmega boards. Conceptually you just need to use any pins that handle hardware serial (which are fixed for the board, see the block diagram) or it is possible you can use SoftwareSerial library and use many more pins.

Have you got the jumper set right for the US-100 to output serial data (vs. the trigger/echo method)? I think if the jumper is present it will use serial.

Rather than using the library, I suggest you connect your US-100 with a very basic program that just passes through whatever your computer or the nodemcu is sending. Then send some test messages to see if the US-100 responds.

Sorry, I can't help much more than that - I don't have a device to test with nor the time to do it ATM :)

jonathand131 commented 5 years ago

Fix proposal in PR #7