Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Kurti

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    K
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 0
    • Groups 0

    Kurti

    @Kurti

    0
    Reputation
    8
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Kurti Follow

    Latest posts made by Kurti

    • RE: Ansteuerung eines Digital-Potentiometers (z.B. MCP4151)

      @kurti test

      posted in Skripten / Logik
      K
      Kurti
    • Ansteuerung eines Digital-Potentiometers (z.B. MCP4151)

      Hallo Community,
      hat vielleicht jemand Erfahrung in der Ansteuerung von Digital-Potentiometern mittels IoBroker und Raspberry? Ich versuche das Digi-Pot MCP4151 über seine SPI-Schnittstelle (Seriell Peripheral Interface) aus IoBroker heraus mittels JavaScript gemäß nachfolgendem Script anzusteuern, bekomme aber immer die Fehlermeldung "Error opening SPI-device". Vielleicht kann mir jemand helfen, die Fehlerursache zu beseitigen.

      const SpiDevice = require('/opt/iobroker/node_modules/spi-device/spi-device.js');
      
      // Define the SPI configuration for the MCP4151
      const spiConfig = {
        mode: SpiDevice.MODE0,     // SPI mode 0
        chipSelectHigh: false,     // Active low CS
        maxSpeedHz: 20000,       // Maximum SPI clock speed (1 MHz)
      };
      
      // Define the MCP4151 command to set the potentiometer value
      const MCP4151_WRITE_COMMAND = 0x00;
      
      // Function to set the potentiometer value
      function setPotentiometerValue(spi, value) {
        const message = [{
          sendBuffer: Buffer.from([MCP4151_WRITE_COMMAND, value]),
          byteLength: 2,
        }];
      
        spi.transfer(message, (error) => {
          if (error) {
            console.error('SPI transfer error:', error);
          } else {
            console.log(`Potentiometer value set to ${value}`);
          }
          spi.close(() => {
            console.log('SPI device closed');
          });
        });
      }
      
      // Open the SPI device
      const spi = SpiDevice.open(0, 0, spiConfig, (error) => {
        if (error) {
          // @ts-ignore
          console.error('Error opening Rie-SPI device:', error);
        } else {
          // Set the potentiometer value (0-255)
          const potValue = 128; // Change this to your desired value
          setPotentiometerValue(spi, potValue);
        }
      });
      

      MOD-EDIT: Code in code-tags gesetzt!

      posted in Skripten / Logik
      K
      Kurti
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo