PowerShell-IoT icon indicating copy to clipboard operation
PowerShell-IoT copied to clipboard

Detect if I2C is enable and possibly enable it if user agrees

Open DanielSSilva opened this issue 7 years ago • 4 comments

For what I've seen, enable the I2C "manually" seems quite easy, only requiring to edit:

  • the /etc/modules file to add i2c-dev
  • the /boot/config.txt file and uncomment the dtparam=i2c_arm=on entry.

If this is all that it takes, when the user imports this module, we can check if the i2c is already enabled and display a warning if it's not. Even better would be to prompt the user if he wants to enable it (avoiding the process of running sudo raspi-config and search for that).

Does this seems feasible/ make sense?

DanielSSilva avatar May 09 '18 21:05 DanielSSilva

It would certainly be beneficial to have a PowerShell way of enabling I2C (and, as extension, other interfaces). Though doing this during module import may not be the best place because user may be wanting to use interface other than I2C. Currently with disabled I2C Get-I2CDevice will give Unable to open I2C device: No such file or directory error. At a minimum we need to improve this error message to something like "Unable to open I2C device; please enable I2C interface using ..." Ideally, I think, we should implement 2 cmdlets like: Enable/Disable-ArmInterface -I2C/-SPI/<others> and maybe add a call to them when Get-I2CDevice gets above-mentioned error.

anmenaga avatar May 09 '18 21:05 anmenaga

We should also make sure these aren't pi specific (Or write them in an easy way to support other devices) since we do eventually want to support other devices.

TylerLeonhardt avatar May 09 '18 22:05 TylerLeonhardt

@anmenaga I understand your point, although the idea was not to "prevent" the user from using the module, but to warn/alert him that I2C (or other interface) was not enabled. Although this could become annoying if the user frequently import this module but don't care about this interface (maybe this is what you mean). Don't know if this could be solved with a flag on the Import-Module (don't know if it's even possible, but doesn't really makes sense). The call as you referred would make sense in that way.

@tylerl0706 I'm not familiar with the other devices, but isn't this something specific for each device? Seems like it's a configuration that can vary from device do device (worst case, from OS to OS)

DanielSSilva avatar May 09 '18 22:05 DanielSSilva

We can start with Pi specific commands :)

TylerLeonhardt avatar May 10 '18 20:05 TylerLeonhardt