Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. Ansteuerung eines Digital-Potentiometers (z.B. MCP4151)

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    3.1k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.1k

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.4k

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

Scheduled Pinned Locked Moved Skripten / Logik
3 Posts 2 Posters 209 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kurti
    wrote on last edited by Homoran
    #1

    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
    0
    • K Kurti

      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 Offline
      K Offline
      Kurti
      wrote on last edited by
      #2

      @kurti test

      geschildG 1 Reply Last reply
      0
      • K Kurti

        @kurti test

        geschildG Offline
        geschildG Offline
        geschild
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        Support us

        ioBroker
        Community Adapters
        Donate

        616

        Online

        32.6k

        Users

        82.3k

        Topics

        1.3m

        Posts
        Community
        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
        ioBroker Community 2014-2025
        logo
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Home
        • Recent
        • Tags
        • Unread 0
        • Categories
        • Unreplied
        • Popular
        • GitHub
        • Docu
        • Hilfe