0

BME280 on BeagleBone Black Wireless
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Wed Apr 19, 2017 2:57 am

I've now documented how to run config-pin at bootup:

#1: Create script file
sudo vi /usr/bin/enable-i2c-pins.sh
#!/bin/bash

config-pin p9.17 i2c
config-pin p9.18 i2c

sudo chmod 755 /usr/bin/enable-i2c-pins.sh

#2: Create systemd service file
sudo vi /lib/systemd/system/enable-i2c-pins.service
[Unit]
Description=Enable I2C pins
After=generic-board-startup.service

[Service]
Type=simple
ExecStart=/usr/bin/enable-i2c-pins.sh

[Install]
WantedBy=multi-user.target


#3: Enable the new systemd service
sudo systemctl daemon-reload
sudo systemctl enable enable-i2c-pins.service

#4: Reboot and test
sudo systemctl status enable-i2c-pins.service
debian@beaglebone:~$ sudo systemctl status enable-i2c-pins.service
● enable-i2c-pins.service - Enable I2C pins
Loaded: loaded (/lib/systemd/system/enable-i2c-pins.service; enabled)
Active: inactive (dead) since Wed 2017-04-19 06:35:06 UTC; 48s ago
Process: 649 ExecStart=/usr/bin/enable-i2c-pins.sh (code=exited, status=0/SUCCESS)
Main PID: 649 (code=exited, status=0/SUCCESS)

Apr 19 06:35:05 beaglebone sudo[664]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/bash -c echo i2c > /sys/devices/platform/ocp/ocp:P9_17_pinmux/state
Apr 19 06:35:05 beaglebone sudo[664]: pam_unix(sudo:session): session opened for user root by (uid=0)
Apr 19 06:35:05 beaglebone sudo[664]: pam_unix(sudo:session): session closed for user root
Apr 19 06:35:06 beaglebone sudo[677]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/bash -c echo i2c > /sys/devices/platform/ocp/ocp:P9_18_pinmux/state
Apr 19 06:35:06 beaglebone sudo[677]: pam_unix(sudo:session): session opened for user root by (uid=0)
Apr 19 06:35:06 beaglebone sudo[677]: pam_unix(sudo:session): session closed for user root


config-pin -q p9.17 && config-pin -q p9.18
debian@beaglebone:~$ config-pin -q p9.17 && config-pin -q p9.18
P9_17 Mode: i2c
P9_18 Mode: i2c

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Wed Apr 26, 2017 2:56 pm

I'm stuck on step one. After typing "sudo vi /usr/bin/enable-i2c-pins.sh" and then
Code: Select all | TOGGLE FULL SIZE
#!/bin/bash

config-pin p9.17 i2c
config-pin p9.18 i2c


I am stuck here. What do I need to do to move on from this point?

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Wed Apr 26, 2017 9:21 pm

After you create that file, run:
sudo chmod 755 /usr/bin/enable-i2c-pins.sh

This will make the script executable.

Then create systemd service file:
sudo vi /lib/systemd/system/enable-i2c-pins.service
with this content:
[Unit]
Description=Enable I2C pins
After=generic-board-startup.service

[Service]
Type=simple
ExecStart=/usr/bin/enable-i2c-pins.sh

[Install]
WantedBy=multi-user.target


Enable the new systemd service with these commands:
sudo systemctl daemon-reload
sudo systemctl enable enable-i2c-pins.service

Then reboot your system:
sudo reboot

Check that the service is running:
sudo systemctl status enable-i2c-pins.service

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Wed Apr 26, 2017 10:05 pm

I am unclear on how exactly to create that file. What do I need to press to create the file? I have typed in "sudo vi /usr/bin/enable-i2c-pins.sh" and then I entered #!/bin/bash

config-pin p9.17 i2c
config-pin p9.18 i2c. But I don't know how to leave this screen to then enter "sudo chmod 755 /usr/bin/enable-i2c-pins.sh". I don't have experience with this. I am stuck on this screen. What do I need to do after I enter "#!/bin/bash
config-pin p9.17 i2c
config-pin p9.18 i2c" to create that file? What buttons do I need to push so I can move on to entering "sudo chmod 755 /usr/bin/enable-i2c-pins.sh" ?

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Wed Apr 26, 2017 10:17 pm

The vi editor can be difficult to use if you're new to it. nano editor is more user friendly, so please substitute vi for nano.

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Wed Apr 26, 2017 10:19 pm

I apologise for my lack of experience. I'm having a tough time with this project.

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Wed Apr 26, 2017 10:19 pm

It just occurred to me it is probably simpler if I attach the files and give you instructions to install them.
Attachments
enable-i2c-pins-service.txt
(170 Bytes) Downloaded 23 times
enable-i2c-pins-sh.txt
(55 Bytes) Downloaded 22 times

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Wed Apr 26, 2017 10:28 pm

These commands will download the files and install them:

wget -O /tmp/enable-i2c-pins.service 'https://forums.adafruit.com/download/file.php?id=46691'

wget -O /tmp/enable-i2c-pins.sh 'https://forums.adafruit.com/download/file.php?id=46690'

sudo cp /tmp/enable-i2c-pins.service /lib/systemd/system/enable-i2c-pins.service

sudo cp /tmp/enable-i2c-pins.sh /usr/bin/enable-i2c-pins.sh

sudo chmod 755 /usr/bin/enable-i2c-pins.sh

sudo systemctl daemon-reload

sudo systemctl enable enable-i2c-pins.service

sudo reboot

Verify the service ran at startup and the pins were configured for i2c:

sudo systemctl status enable-i2c-pins.service

config-pin -q p9.17 i2c && config-pin -q p9.18 i2c

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Thu Apr 27, 2017 3:24 pm

I was able to use nano in place of vi as suggested. It worked perfectly with the document that you created https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/doc/run_config-pin_during_startup.md .

For some reason the rtc-ds1307.service is not running the clock_init.sh script on boot. All the files created with nano previously are still there and correct time saved in the DS3231 RTC.
After boot i2cdetect -y -r 1 reflects that config-pin at boot up was successful.
Code: Select all | TOGGLE FULL SIZE
root@beaglebone:/home/debian# sudo i2cdetect -y -r 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77


But I had to execute "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device" again for the BBB to see 0x68 as the RTC .

Code: Select all | TOGGLE FULL SIZE
root@beaglebone:/home/debian# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
root@beaglebone:/home/debian# sudo i2cdetect -y -r 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77                         
root@beaglebone:/home/debian# hwclock -r -f /dev/rtc1
Thu 27 Apr 2017 01:48:23 PM EDT  -0.424391 seconds


Here are the steps and commands I used to create script and service that is not currently working.
Code: Select all | TOGGLE FULL SIZE
mkdir /usr/share/rtc_ds1307
nano /usr/share/rtc_ds1307/clock_init.sh


with the nano text editor open, I copied the following into the clock_init.sh script:
Code: Select all | TOGGLE FULL SIZE
#!/bin/bash
sleep 15
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s -f /dev/rtc1
hwclock -w


Code: Select all | TOGGLE FULL SIZE
nano /lib/systemd/system/rtc-ds1307.service


Code: Select all | TOGGLE FULL SIZE
[Unit]
Description=DS1307 RTC Service
 
[Service]
Type=simple
WorkingDirectory=/usr/share/rtc_ds1307
ExecStart=/bin/bash clock_init.sh
SyslogIdentifier=rtc_ds1307
 
[Install]
WantedBy=multi-user.target


Code: Select all | TOGGLE FULL SIZE
 systemctl enable rtc-ds1307.service


From this tutorial https://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black?view=all

The config-pin at boot-up document that you created was very helpful and it works. Thank you very much for your time in helping me with this project. It really means a lot. It is almost complete. Could not have gotten to this point without you https://forums.adafruit.com/memberlist.php?mode=viewprofile&u=318453.

I am about to move the BME280 and DS3231 from the breadboard to a Adafruit Perma-Proto breadboard that I have been saving for just such an occasion.

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Thu Apr 27, 2017 10:22 pm

It's possible that the RTC setup service is running before the I2C setup service. Try adding After=enable-i2c-pins.service to /lib/systemd/system/rtc-ds1307.service:
[Unit]
Description=DS1307 RTC Service
After=enable-i2c-pins.service

[Service]
Type=simple
WorkingDirectory=/usr/share/rtc_ds1307
ExecStart=/bin/bash clock_init.sh
SyslogIdentifier=rtc_ds1307

[Install]
WantedBy=multi-user.target

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Fri Apr 28, 2017 12:58 pm

It worked perfectly!! As you said, the RTC setup service was running before the i2c setup service. Adding "After=enable-i2c-pins.service" to "/lib/systemd/system/rtc-ds1307.service" solved the issue.
I am overwhelmed with joy. Complete success!! Couldn't have done it without you. You made this possible. I'm very thankful for your assistance. You are definitely worthy of an Admin of the year award. Your expertise with the BeagleBone is a great asset to the community and we are very fortunate to have you. Thank you so very much for your time and work in helping me with this project. Drewfustini saved the day!

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by trent_darkside on Fri Apr 28, 2017 1:04 pm

Here is a photo of the BeagleBone Black Wireless, Adafruit DS3231 Precision I2C RTC, Adafruit BME280 pressure/temp/humidity sensor, and the Adafruit Power Boost 1000c successfully working together. Thank you Adafruit for making this possible.
Attachments
DSC_0870.JPG
DSC_0870.JPG (72.63 KiB) Viewed 515 times

trent_darkside
 
Posts: 41
Joined: Wed Nov 23, 2016 11:11 am

Re: BME280 on BeagleBone Black Wireless

by drewfustini on Mon May 01, 2017 2:16 am

Awesome to see it is working! :)

drewfustini
 
Posts: 718
Joined: Sat Dec 26, 2015 1:19 pm

Please be positive and constructive with your questions and comments.