arduivis

a bi-directional communication paradigm for programming languages & microcontrollers

Getting Started FAQ Projects
    MaxMSP Pure Data Python NodeJS

    Python - Model #2: Input

    Abstract

    This is an example of how to read a slider from MaxMSP and write the values to Python in the terminal.

    Arduino

     
    /* 
    
    ~~~~~~~ arduivis - Python ~~~~~~~
    ~~~~~~~~ model#2: input ~~~~~~~~~
    
    MaxMSP: arduivis_python_model2_input.maxpat
    Python: arduivis_python_model2_input.py
    
    This is an example of how to read a slider from 
    MaxMSP and write the values to Python in the 
    terminal.
    
    synthesized by Christopher Konopka
    
    This example code is in the public domain.
    
    */
    
    void setup() 
    { 
      //  Create/open serial port
        Serial.begin(9600);   
    }
    
    void loop() 
    {
      // Slider from MaxMSP 
      int maxmspSlider;
    
      // Parse incoming MaxMSP slider values
      // from MaxMSP, thru Arduino, to Python    
      maxmspSlider = Serial.parseInt();  
    }
    

    Python

    
    #____________________________________________________
    #
    # ~~~~~~~ arduivis - Python ~~~~~~~
    # ~~~~~~~~ model#1: output ~~~~~~~~~
    #
    # Python: arduivis_python_model1_output.py
    # MaxMSP: arduivis_python_model1_output.maxpat
    #
    # This is an example of how to send data from 
    # Python to MaxMSP by using an Arduino as 
    # a serial communication hub
    #
    # synthesized by Christopher Konopka
    #
    # This example code is in the public domain.
    #
    #____________________________________________________
    
    # Import pySerial
    import serial
    
    # Port Name
    # To find out the correct port type the line below into the terminal
    # python -m serial.tools.list_ports
    board = '/dev/cu.usbmodem1451'
    
    # Baud Rate
    # Match baud rate with the rate used in the Arduino sketch and the Max patch
    baud = 9600
    
    # Define the connected port
    arduino = serial.Serial(board, baud, timeout=1)
    
    # Keep the data flowing with an infinite while loop
    infinite = 1
    
    while (infinite == 1):
    
      # Read each line of the serial output 
      output = arduino.readline()
    
      # Takes input from the command-line
      toArduino = raw_input('Write to Serial buffer: ')
    
      # Print each line of the serial output
      # print output
      print('Write to Serial buffer', toArduino)
      arduino.write(toArduino+ '\n')
    

    MaxMSP

    some_text