I am making use of some python code for recovering data from a BME280 sensor. The matlab code below code executes without any problem from my copy of Matlab running on a PC.
function blinkLED1()
if coder.target( 'MATLAB' )
fidLog = fopen( 'blinkLED_pc.log', 'w' );
fprintf( fidLog, '%s \n', 'running on pc' );
else
fidLog = fopen( 'blinkLED_pi.log', 'w' );
fprintf( fidLog, '%s \n', 'running on pi' );
end
r= raspi();
fprintf( fidLog, '%s \n', 'turning on LED' );
writeLED(r,"LED0", 1);
fprintf( fidLog, '%s \n', 'sleeping for 0.5 seconds' );
system(r, 'sleep 0.5' );
fprintf( fidLog, '%s \n', 'turning off LED' );
writeLED(r,"LED0", 0);
result = system( r, 'pwd' );
fprintf( fidLog, '%s \n', result );
result = system( r, 'python bme280.py' );
fprintf( fidLog, '%s \n', result );
fclose( fidLog );
log file
------------
running on pc
turning on LED
sleeping for 0.5 seconds
turning off LED
/home/pi
Chip ID : 96
Version : 0
Temperature : 23.33 C
Pressure : 1009.74914285 hPa
Humidity : 61.858241144 %
-------------------
I have no problem deploying this code via the usual route (board = targetHardware('Raspberry Pi' ), deploy(board,'blinkLED1' )). However, on execution on the pi the python call fails due to an import error.
log file
-------------
running on pi
turning on LED
sleeping for 0.5 seconds
turning off LED
/home/pi
Traceback (most recent call last):
File "/home/pi/bme280.py", line 21, in <module>
import smbus
ImportError: No module named smbus
---------------------
I have checked that the module smbus is on the sys.path (under /home/pi/.local/lib/python2.7/site-packages) and it is obviously visible when I attempt execution from the PC. It is not obvious to me why this should fail when deployed.