Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Adafruit_BME280 to latest, add Adafruit_BusIO #2407

Merged
merged 10 commits into from
Nov 2, 2021

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Oct 28, 2021

I don't have any hardware to test this, but builds OK.

todo:

  • Add sample for integration testing
  • Update Adafruit_Sensor to latest
  • Add required Adafruit_BusIO library and patch to build for other Sming architectures
  • Fix TwoWire behaviour - begin() should not change configured pins
  • Verify build for Esp8266, Host and Esp32 architectures
  • Verify operation with real hardware

@slaff
Copy link
Contributor

slaff commented Oct 29, 2021

@Vity01 Can you check this PR please?

@slaff slaff added this to the 4.5.0 milestone Oct 29, 2021
.gitmodules Outdated Show resolved Hide resolved
@Vity01
Copy link

Vity01 commented Oct 29, 2021

@slaff what's the proper way to test it? To apply the patch locally or shall I checkout/switch into develop branch locally?

@slaff
Copy link
Contributor

slaff commented Oct 29, 2021

what's the proper way to test it? To apply the patch locally or shall I checkout/switch into develop branch locally?

You can use the following commands:

cd $SMING_HOME 
git remote add mikee47 https://github.com/mikee47/Sming.git
git fetch mikee47 update/adafruit-bme280
git checkout update/adafruit-bme280

After that go to your application that is using Adafruit_BME280 and type the following:

make clean
make Adafruit_BME280-build all

You should have now the newer Adafruit_BME280 library and can test it from here.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

@Vity01 I'll add a sample to test this library shortly. It'll build, perhaps you could debug/test it?

@Vity01
Copy link

Vity01 commented Oct 29, 2021

@mikee47 yes
@slaff those 2 last commands don't refresh the library

Vity@PRGA-004922 MINGW64 /c/tools/Sming/Sming/Libraries (update/adafruit-bme280)
$ git checkout update/adafruit-bme280
Already on 'update/adafruit-bme280'
M       Sming/Components/FlashString
M       Sming/Components/IFS
M       Sming/Libraries/Adafruit_BME280_Library
Your branch is up to date with 'mikee47/update/adafruit-bme280'.

Vity@PRGA-004922 MINGW64 /c/tools/Sming/Sming/Libraries (update/adafruit-bme280)
$ cd Adafruit_BME280_Library/

Vity@PRGA-004922 MINGW64 /c/tools/Sming/Sming/Libraries/Adafruit_BME280_Library ((1.0.6))
$ make clean
make: *** No rule to make target `clean'.  Stop.

Vity@PRGA-004922 MINGW64 /c/tools/Sming/Sming/Libraries/Adafruit_BME280_Library ((1.0.6))
$ make Adafruit_BME280-build all
make: *** No rule to make target `Adafruit_BME280-build'.  Stop.

@slaff
Copy link
Contributor

slaff commented Oct 29, 2021

After that go to your application

@slaff those 2 last commands don't refresh the library

Make sure to CD to your application :)

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

@Vity01 Run make submodules-clean first, that'll force a re-fetch.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

Hint: As the sample doesn't require networking you can speed up build times using make DISABLE_NETWORK=1

@Vity01
Copy link

Vity01 commented Oct 29, 2021

Playing with branches and submodules is a game which I never win.

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink (update/adafruit-bme280)
$ make

Basic_Blink: Invoking 'all' for Esp8266 (debug) architecture
/usr/bin/make components application
make[1]: Entering directory `/c/tools/Sming/samples/Basic_Blink'

Building c:/tools/Sming/Sming/Arch/Esp8266/Components/esp8266/ESP8266_NONOS_SDK/lib/libcrypto.orig.a c:/tools/Sming/Sming/out/Esp8266/debug/lib/clib-esp8266-4fa62282a284c3e87dc205ebc20b6e70.a
make[2]: *** No rule to make target `c\:/tools/Sming/Sming/Arch/Esp8266/Components/esp8266/crash_handler.c', needed by `crash_handler.o'.  Stop.
make[1]: *** [esp8266-build] Error 2
make[1]: Leaving directory `/c/tools/Sming/samples/Basic_Blink'
make: *** [all] Error 2

also make Adafruit_BME280-build all does not work, but I used the make fetch to download the sources.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

OK, brute force make dist-clean; make

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

Also worth checking you have a clean working area with git status, use git reset --hard or git clean -fd as required

@Vity01
Copy link

Vity01 commented Oct 29, 2021

It's completely broken

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink (update/adafruit-bme280)
$ git reset --hard
HEAD is now at ef82a037 Port bme280test example from library

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink (update/adafruit-bme280)
$ git clean -fd

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink (update/adafruit-bme280)
$ git status
On branch update/adafruit-bme280
Your branch is up to date with 'mikee47/update/adafruit-bme280'.

nothing to commit, working tree clean

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink (update/adafruit-bme280)
$ make dist-clean

Basic_Blink: Invoking 'dist-clean' for Esp8266 (debug) architecture
Using configuration 'standard'
Cleaning all submodules...
Updated 65 paths from the index
Cleaning all samples...
Cleaning documentation...
awk: cmd. line:1: C:/MinGW/msys/1.0/path = .*/ { path = $3 } /url = .*/ { printf "%s=%s ", path, $3 }
awk: cmd. line:1:  ^ syntax error
awk: cmd. line:1: C:/MinGW/msys/1.0/path = .*/ { path = $3 } /url = .*/ { printf "%s=%s ", path, $3 }
awk: cmd. line:1:                        ^ syntax error
awk: cmd. line:1: C:/MinGW/msys/1.0/path = .*/ { path = $3 } /url = .*/ { printf "%s=%s ", path, $3 }
awk: cmd. line:1:                                                 ^ syntax error
awk: cmd. line:1: C:/MinGW/msys/1.0/path = .*/ { path = $3 } /url = .*/ { printf "%s=%s ", path, $3 }
awk: cmd. line:1:                                                      ^ unterminated regexp

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

Not entirely sure what's going on here:

awk: cmd. line:1: C:/MinGW/msys/1.0/path = .*/ { path = $3 } /url = .*/ { printf "%s=%s ", path, $3 }
awk: cmd. line:1:  ^ syntax error

If I run awk --version I get GNU Awk 3.1.7. Are you getting something different perhaps?

Anyway, this problem is with the documentation build which isn't required. To avoid getting side-tracked use make clean components-clean; make instead.

Hint: You can get descriptions of all these various build targets using make help.

@Vity01
Copy link

Vity01 commented Oct 29, 2021

I get newer version

Vity@PRGA-004922 MINGW64 /c/tools/Sming/samples/Basic_Blink ((4.4.1))
$ awk --version
GNU Awk 5.0.0, API: 2.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)

I will try to play with the clean targets, but I think the problem is related to Windows + Awk.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

I would recommend trying out vscode with WSL2, it's a much better experience on Windows. https://sming.readthedocs.io/en/stable/getting-started/windows/wsl.html

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

@Vity01
Copy link

Vity01 commented Oct 29, 2021

@mikee47 I tried to install Sming to WSL, but it's ending with errors...

vity@PRGA-004922:/opt/sming/samples/Basic_Blink$ make
/opt/sming/Sming/Arch/Esp8266/build.mk:56: *** ESP_HOME not set correctly: "/opt/esp-open-sdk".  Stop.

There is no such path, I don't know if there is something missing or it should use a different path...(there are esp-idf-4.3, esp-quick-toolchain, esp32)

Same for VScode , it's possible to call make from a common cmd.exe and the build passes, but from VScode it launches powershell, where the calling make fails because of improper linux paths/calling Bash...

> Executing task in folder Basic_Blink: make -j SMING_ARCH=Host <


Basic_Blink: Invoking 'all' for Host (debug) architecture
/c/tools/Sming/samples/Basic_Blink/"C:/MinGW/msys/1.0/bin/make.exe" components application
/bin/sh: /c/tools/Sming/samples/Basic_Blink/C:/MinGW/msys/1.0/bin/make.exe: No such file or directory
make.exe": *** [all] Error 127
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command make -j SMING_ARCH=Host" terminated with exit code: 1.

The tooling is a big Sming problem, since my first experiments 3 years ago...

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 29, 2021

Two critical environment variables need to be made available for vscode. There's a hint in the Sming/Tools/export.sh file (should probably add that to the docs.) which suggests adding these to your .bashrc file.

https://github.com/SmingHub/Sming/blob/e66e4f3049267df751c7de5f2e4675e1b2e50fbc/Tools/export.sh

Edit ~/.bashrc and add the following lines to the end:

export SMING_HOME=/opt/sming/Sming
export ESP_HOME=/opt/esp-quick-toolchain

You'll need to restart vscode but then it should pick them up. From your project directory, run make ide-vscode then do File -> open workspace from file. That should get you going.

@slaff
Copy link
Contributor

slaff commented Oct 31, 2021

@mikee47 The build on Windows is failing. Can you check the compilation errors?

BusIO calls `Wire.begin()` so if pins have already been set must not be changed back to defaults.
Default pins depend on selected architecture so ensure those values aren't overridden.
@Vity01
Copy link

Vity01 commented Oct 31, 2021

Current status:

  • I cloned @mikee47 's branch from scratch to the clean c:/tools/sming folder (I suppose it's based on develop branch)
  • External make build is working fine (if I don't count 1 internal compiler crash error...), no errors although IDE shows info about unknown constant
    image
  • make flash & the application in my ESP is working fine

Suggestion for the example - could you add a comment for users how to work with another sensor address

	if(!bme.begin() {  // if(!bme.begin(0x76, &Wire)) if you need a specific address

Good job @mikee47 👍 .


Windows related problems: - requires new issues..

Invoking build from the VSCode is not working

/c/tools/Sming/samples/Humidity_BME280/"C:/MinGW/msys/1.0/bin/make.exe" components application
/bin/sh: /c/tools/Sming/samples/Humidity_BME280/C:/MinGW/msys/1.0/bin/make.exe: No such file or directory
make.exe": *** [all] Error 127
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command make -j SMING_ARCH=Esp8266" terminated with exit code: 1.

The problem lies in project.mk

all: checkdirs submodules ##(default) Build all Component libraries
	$(MAKE) components application 

Some VSCode magic sets /c/tools/Sming/samples/Humidity_BME280/"C:/MinGW/msys/1.0/bin/make.exe" as $MAKE. External build contains only just $MAKE = make and the build passes. My workaround is to update make components application instead of $(MAKE) components application in sming/project.mk.

make ide-vscode still give warnings about invalid paths (because of invalid paths translation make->setup.py...), vscode includes are generated properly

Warning! '/C/tools/esp-quick-toolchain/gnu20/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++.exe' doesn't exist
Warning! '/C/tools/esp-quick-toolchain/gnu20/xtensa-lx106-elf/bin/xtensa-lx106-elf-gdb.exe' doesn't exist

make ide-vscode generates wrong commands for PowerShell in tasks.json

"command": "make clean components-clean SMING_ARCH=${command:cpptools.activeConfigName} && make -j ENABLE_GDB=",
"command": "make clean components-clean SMING_ARCH=${command:cpptools.activeConfigName} && make -j ENABLE_GDB=1",

There should be ; instead of &&. I had to fix it manually.

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe IDE project files should not be included

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slaff Now we have make ide-eclipse these could all be removed perhaps...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slaff Now we have make ide-eclipse these could all be removed perhaps...

Yes, I agree. May be we can leave just the Sming Framework .[c]project files. Of course such a change should be a separate PR with update to the documentation too related to this change.

Wire.pins(SDA, SCL);
#endif

if(!bme.begin()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion add this comment to the line, it can help beginners to discover this possibility
if(!bme.begin() { // if(!bme.begin(0x76, &Wire)) if you need a specific address

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 31, 2021

@Vity01 Thank you for review! #2410 should fix vscode issues, except for missing COM_SPEED_SERIAL - I'll look at that just now.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 31, 2021

@Vity01 The problem with make occurs when running under powershell. This is the default shell for vscode running under Windows. (I tend to avoid powershell and have mine set to cmd.exe.) For some reason the MAKE variable isn't constructed correctly. Try make -p | grep MAKE_COMMAND:

MAKE_COMMAND := /s/sandboxes/sming-tmp/samples/Humidity_AM2321/C:/MinGW/msys/1.0/bin/make.exe

This affects recursive use of make. Probably an issue with this particular version of make, but it's easily fixed by removing the prefix (which corresponds to $(CURDIR)/.

@mikee47
Copy link
Contributor Author

mikee47 commented Oct 31, 2021

Re. internal compiler crash error this happens when running make -j under Windows (never a problem in linux). Solution is to restrict usage appropriately, e.g. make -j8.

@Vity01
Copy link

Vity01 commented Nov 1, 2021

@Vity01 The problem with make occurs when running under powershell. This is the default shell for vscode running under Windows. (I tend to avoid powershell and have mine set to cmd.exe.)

I can confirm the MAKE_COMMAND variable mess:
MAKE_COMMAND := /c/Users/Vity/"C:/MinGW/msys/1.0/bin/make.exe"

For VSCode - even the Terminal is set to cmd.exe in the VSCode settings, it still launches the powershell,
image

I found a workaround.
It's necessary to update VSCode settings.json - just to add

"terminal.integrated.defaultProfile.windows": "Command Prompt",

There is some discussion https://stackoverflow.com/questions/69047142/vscode-is-suddenly-defaulting-to-powershell-for-integrated-terminal-and-tasks
but obviously it's still bugged in 1.61+.

now the Terminal->New Terminal launches cmd.exe and not the Powershell and also the build is launched on Cmd.exe.
I am not sure if it's possible to set it up for project settings somehow - so the Sming users would use the Cmd.exe by default.

@mikee47
Copy link
Contributor Author

mikee47 commented Nov 1, 2021

I am not sure if it's possible to set it up for project settings somehow

Excellent find! Yes, the same setting can be added to sming.code-workspace.

@mikee47
Copy link
Contributor Author

mikee47 commented Nov 1, 2021

Although my feeling is that there is no good excuse for not being able to run the build from powershell, if that is what the user prefers. Instead of modifying the template I'll add a note to the documentation.

@Vity01
Copy link

Vity01 commented Nov 1, 2021

I agree the PShell should work, but fixing it is another level of complexity and another step for Sming users. I would recommend to update the sming.code-workspace.
The only Pshell advantage I see is the text coloring.
Of course it's good to mention it in doc.

@slaff
Copy link
Contributor

slaff commented Nov 2, 2021

@mikee47 Is also this PR ready for merging?

@mikee47
Copy link
Contributor Author

mikee47 commented Nov 2, 2021

@slaff Yes, ready.

@slaff slaff merged commit 49a236e into SmingHub:develop Nov 2, 2021
@mikee47 mikee47 deleted the update/adafruit-bme280 branch November 2, 2021 12:04
@slaff slaff mentioned this pull request Nov 16, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants