My code doesn't work for motor control via the Raspberry?

I'm trying to build a controller for a miniature crane using a Raspberry Pi. The controller runs via an HTML website (according to Chat-gpt, this is the correct one; just ask if you need the script). As soon as I press the button on Putty, I get a message saying that the GPIO pin isn't a pin on the Raspberry Pi.

This is the code:

 using Microsoft.AspNetCore.Mvc; using System.Device.Gpio; using System.Numerics; namespace Kransteuerung_MEKW.Controllers {  [ApiController]  [Route("[controller]")]  public class CraneController : ControllerBase  {    private readonly GpioController _gpioController;    private readonly ILogger<CraneController> _logger;    public CraneController(ILogger<CraneController> logger)    {      _logger = logger;      _gpioController = new GpioController(PinNumberingScheme.Board);      var allOutputPinNumbers = new List<int>{ 3 };      _logger.LogInformation("Setze alle GPIO Pins auf Output start");      foreach (int pinNumber in allOutputPinNumbers)      {        var pin = _gpioController.OpenPin(pinNumber);        pin.SetPinMode(PinMode.Output);        pin.Write(PinValue.Low);      }      _logger.LogInformation("Setze alle GPIO Pins auf Output fertig");           }        [HttpGet()]    public string Info()    {      return "Mögliche Posts: crane/turnLeftStart oder crane/turnLeftStop";    }    [HttpPost("turnLeftStart")]    public void TurnLeftStart()    {      _logger.LogInformation("Kran dreht links start");            var pin = _gpioController.OpenPin(3);      pin.Write(PinValue.High);    }    [HttpPost("turnRightStart")]    public void TurnRightStart()    {      _logger.LogInformation("Kran dreht rechts start");             var pin = _gpioController.OpenPin(4);      pin.Write(PinValue.High);    }    [HttpPost("turnLeftStop")]    public void TurnLeftStop()    {      _logger.LogInformation("Kran dreht links stop");      var pin = _gpioController.OpenPin(3);      pin.Write(PinValue.Low);    }    [HttpPost("turnRightStop")]    public void TurnRightStop()    {      _logger.LogInformation("Kran dreht rechts stop");      var pin = _gpioController.OpenPin(4);      pin.Write(PinValue.Low);    }  } }
(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Suiram1
10 months ago

In the logs, the exception should be logged that causes the error. If you hate access to the console output, it should be logged there. If you can’t access the console, use a 3rd Party Lib like Serilog to write the logs into a file.