pjgpetecodes / rpirobot

A Raspberry Pi Robot Arm using .NET
47 stars 5 forks source link

Using raspberry Pi 2 #6

Open eoinward opened 3 years ago

eoinward commented 3 years ago

Currently on your Garage course and working "On the Flash LEDs": https://github.com/pjgpetecodes/rpirobot/blob/main/workshop/06-flash-led.md

I am getting an error using a PI 2

Unhandled exception. System.PlatformNotSupportedException: This driver is generic so it can not perform conversions between pin numbering schemes. at System.Device.Gpio.Drivers.SysFsDriver.ConvertPinNumberToLogicalNumberingScheme(Int32 pinNumber) at System.Device.Gpio.GpioController.GetLogicalPinNumber(Int32 pinNumber) at System.Device.Gpio.GpioController.OpenPinCore(Int32 pinNumber) at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber) at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber, PinMode mode) at robot_firmware.Program.Main(String[] args) in /home/pi/share/robot_firmware/Program.cs:line 19

You can force the System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver rather than it falling through to the generic

         var assembly = typeof(GpioDriver).Assembly;

        var driverType = assembly.GetType("System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver");

         var ctor = driverType.GetConstructor(new Type[]{});

         var driver = ctor.Invoke(null) as GpioDriver;

         GpioController controller = new GpioController(PinNumberingScheme.Board, driver);

Maybe just a note for future users if they are still on an old Pi they could just add to all the code: Solution form here: https://www.gitmemory.com/issue/dotnet/iot/1329/735402962

pjgpetecodes commented 3 years ago

That's interesting... Thanks @eoinward ... I'll add a note to the workshop... Thanks!

pjgpetecodes commented 3 years ago

Done! I've added a note there, and also to my blog post here... https://bit.ly/dotnet5pi

pjgpetecodes commented 3 years ago

Interestingly, this is supposed to be fixed... https://github.com/dotnet/iot/issues/1329

eoinward commented 3 years ago

I just double checked my Pi version, I had used an older Pi (I have a 2 and 3):

cat /proc/device-tree/model
Raspberry Pi 2 Model B Rev 1.1

Probably not many people using a Pi 2 anymore, not sure if there is much value in the note. Apologies with the miss information.

pjgpetecodes commented 3 years ago

Can you do me a favout @eoinward and open up your csproj file and check which version of the GPIO package you're using please?

eoinward commented 3 years ago
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Device.Gpio" Version="1.3.0" />
  </ItemGroup>

</Project>
pjgpetecodes commented 3 years ago

Interesting then...

It clearly isn't fixed here then eh... https://github.com/dotnet/iot/issues/1329.

Can you run the following commands one by one on your pi and let me know what you get back?

pinout

cat /proc/cpuinfo

cat /proc/device-tree/model

eoinward commented 3 years ago

pi@raspberrypi:~ $ cat /proc/cpuinfo processor : 0 model name : ARMv7 Processor rev 5 (v7l) BogoMIPS : 38.40 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5

processor : 1 model name : ARMv7 Processor rev 5 (v7l) BogoMIPS : 38.40 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5

processor : 2 model name : ARMv7 Processor rev 5 (v7l) BogoMIPS : 38.40 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5

processor : 3 model name : ARMv7 Processor rev 5 (v7l) BogoMIPS : 38.40 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xc07 CPU revision : 5

Hardware : BCM2835 Revision : a21041 Serial : 000000008d6899d0 Model : Raspberry Pi 2 Model B Rev 1.1

eoinward commented 3 years ago

Raspberry Pi 2 Model B Rev 1.1

pjgpetecodes commented 3 years ago

Oooo! you're running a Pi2 not a Pi3 it reckons then!

eoinward commented 3 years ago

Yes that is it fix on Pi3 still an issue on Pi2

eoinward commented 3 years ago

that said using var driverType = assembly.GetType("System.Device.Gpio.Drivers.RaspberryPi3LinuxDriver"); iss working fine on my Pi2

eoinward commented 3 years ago

Might see if I can get a PR in to fix in in Pi2, should be a bit of fun: https://github.com/dotnet/iot/issues/1270

pjgpetecodes commented 3 years ago

Yeah... The issue will be that your BCM id isn't in the https://github.com/krwq/iot/blob/466fb50222726c318909ef0b0ee763056cc6cfef/src/System.Device.Gpio/System/Device/Gpio/RaspberryBoardInfo.cs file...

What did the pinout command give you? Feel free to upload a PNG...

eoinward commented 3 years ago

image

eoinward commented 3 years ago

image

eoinward commented 3 years ago

Like you said looks like there are 2 Model 2 boards but only one is listed here: image

image

pjgpetecodes commented 3 years ago

Your BCM id is actually in the https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/Gpio/RaspberryBoardInfo.cs file...

0x1041

image

This is the file that determines which board you have.,..

So there must be something else wrong...

pjgpetecodes commented 3 years ago

I wonder... Is it worthwhile just checking trying using the nightly package maybe?

https://github.com/dotnet/iot#net-cli

Just incase, for some reason, this hasn't made it into the nuget package... It can't see why it wouldn't have done tho...