Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Ansteuerung eines Digital-Potentiometers (z.B. MCP4151)

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Ansteuerung eines Digital-Potentiometers (z.B. MCP4151)

    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kurti last edited by Homoran

      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!

      K 1 Reply Last reply Reply Quote 0
      • K
        Kurti @Kurti last edited by

        @kurti test

        geschild 1 Reply Last reply Reply Quote 0
        • geschild
          geschild @Kurti last edited by

          @kurti Vielleicht hilft das hier weiter: https://github.com/fivdi/spi-device

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          1.0k
          Online

          31.7k
          Users

          79.7k
          Topics

          1.3m
          Posts

          2
          3
          167
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo