Inputs & Outputs / Pins

Connecting Your Program to the Physical World

What it is

The Inputs & Outputs / Pins category contains the blocks used to interact directly with the physical pins of the D1 R32.

These blocks allow the program to:

  • Receive digital information.
  • Control digital outputs.
  • Read analog signals.
  • Generate PWM outputs.
  • React immediately to pin changes using interrupts.
  • Generate DAC analog outputs.

What it does

The pins create the connection between the program and electronic components.

Think of the pins as the connection points between your program and the electronic world.


Inputs & Outputs / Pins Blocks

The blocks in this category can be organized into five important families:

DIGITAL → ANALOG INPUT → PWM → INTERRUPTS → DAC


Block Guide

BlockBlock ImageWhat It DoesWhat the Options Mean
HIGH / LOW
Provides a digital logic value.HIGH represents 1. LOW represents 0.
Setup Digital Pin
Configures a selected pin for digital operation.PIN# selects the physical pin. Digital Output configures the pin as an output. The available setup mode should be selected according to whether the pin will send or receive a digital signal.
Digital Output
Sets the selected digital output to HIGH or LOW.HIGH → 1 and LOW → 0.
Digital Input
Reads the current digital value of a pin.The returned value represents the current digital state of the selected pin.
Setup Analog Input
Configures an ADC input on the selected analog-capable pin.The selected pin determines which ADC input is created.
ADC Attenuation
Changes the ADC attenuation setting, which changes the input-voltage range handled by the ADC.Available generated settings: ATTN_11DB, ATTN_6DB, ATTN_2_5DB, ATTN_0DB.
ADC Resolution
Configures the ADC reading resolution.Available generated resolutions: 16-bit, 12-bit, 11-bit, 10-bit, 9-bit.
Get Analog Input
Reads the selected ADC input. Clu-Blocks Pro generates an analog reading using read_u16() or read().
Setup PWM Output
Configures the selected pin for PWM output.PIN# selects the PWM-capable output pin.
PWM Value
Sets the PWM duty value.The numerical input determines the generated PWM duty value.
PWM Frequency
Sets the PWM frequency.The numerical field specifies the frequency used by the PWM output.
Attach Interrupt
Configures a pin to trigger a function when the selected signal change occurs.Available generated triggers are RISING, FALLING, and RISING + FALLING.
Interrupt Function
Contains the instructions executed by the interrupt handler.The visible function is attachInterrupt_func.
Setup DAC Output
Configures a DAC-capable pin for analog output.PIN# selects the DAC output pin.
DAC Output
Sends a numerical value to the configured DAC output.The numerical input provides the DAC output value.

1. Digital Signals

Digital signals have two possible logical states:

StateGenerated ValueSimple Meaning
HIGH1ON / Active
LOW0OFF / Inactive

Digital = two states: HIGH or LOW.


2. Setting Up a Digital Pin

Before controlling a digital output, the pin must be configured for the required purpose.

For example, the corresponding output configuration can generate:

pin26 = machine. Pin(26, machine.Pin.OUT)


3. Digital Output

A Digital Output block changes the state of a configured output.

The program can send:

HIGH or: LOW


4. Digital Input

A Digital Input reads the current state of a pin.

The corresponding read operation is:

pin26.value()

The program can then use the returned state with Logic, Control, or Serial Port blocks.


5. Analog Input / ADC

Analog input introduces an important new concept.

Instead of simply distinguishing between HIGH and LOW, the ADC converts an analog signal into a numerical reading that the program can use.


6. Setting Up the ADC

Clu-Blocks Pro creates an ADC associated with the selected pin.

adc2 = machine.ADC(machine.Pin(2))

The adc2 reference can then be used by the other analog-input blocks.


7. ADC Attenuation

The block does not simply select an arbitrary “reference voltage.” The generated MicroPython changes the ADC attenuation setting.

Clu-Blocks Pro generates four possibilities:

Block OptionGenerated MicroPython Setting
3.3VATTN_11DB
2.2VATTN_6DB
1.5VATTN_2_5DB
1.2VATTN_0DB
adc2.atten(machine.ADC.ATTN_11DB)
or:
adc2.atten(machine.ADC.ATTN_0DB)

This setting changes the ADC configuration used for the incoming analog signal.


8. ADC Resolution

The second ADC configuration block controls the resolution of the analog conversion.

The real available options generate:

ResolutionGenerated Setting
16-bitWIDTH_16BIT
12-bitWIDTH_12BIT
11-bitWIDTH_11BIT
10-bitWIDTH_10BIT
9-bitWIDTH_9BIT
adc2.width(machine.ADC.WIDTH_12BIT)

Attenuation and resolution are different settings. Attenuation relates to the ADC input configuration, while resolution determines the number of bits used for the conversion.


9. Reading an Analog Value

After configuring the ADC, the program can obtain the analog reading.

Clu-Blocks Pro generates:

adc2.read_u16() #for 16 bits
or
adc2.read() #for 12,11, 10 y 9 bits

10. PWM Output

PWM stands for:

Pulse Width Modulation

The category provides three related operations:

SETUP → DUTY VALUE → FREQUENCY


Setup PWM

Clu-Blocks Pro generates:

pwm26 = machine.PWM(machine.Pin(26))

The selected pin becomes the PWM output represented by: pwm26


PWM Duty Value

The visible example uses: 0

and Clu-Blocks Pro generates:

pwm26.duty_u16(0)

The value controls the PWM duty setting.

Think of the PWM value as controlling how much of each rapid pulse cycle is active.

This can later be used in applications such as output-level control.


PWM Frequency

The visible example uses: 2000

and generates:

pwm26.freq(2000)

The frequency controls how rapidly the PWM cycles repeat.

So students should distinguish:

  • PWM Value → HOW MUCH
  • PWM Frequency → HOW FAST THE PULSES REPEAT

11. Interrupts

Interrupts introduce a more advanced way for a program to react to an input.

Instead of repeatedly checking a pin in the normal program flow, an interrupt associates a pin event with a handler function.

Conceptually:

Pin Changes → Interrupt Trigger → Handler Function


RISING

The generated trigger is:

machine.Pin.IRQ_RISING

The event occurs on the transition represented by the RISING trigger.


FALLING

The generated trigger is:

machine.Pin.IRQ_FALLING

The event occurs on the transition represented by the FALLING trigger.


RISING + FALLING

Clu-Blocks Pro can also generate:

(machine.Pin.IRQ_RISING | machine.Pin.IRQ_FALLING)

This configures both transitions as triggers.

The available selections can therefore be documented accurately:

TriggerMain Idea
RISINGReact to the rising transition.
FALLINGReact to the falling transition.
RISING + FALLINGReact to either transition.

12. Interrupt Function

ACTION

Instructions associated with the interrupt function

Advanced Concept: Interrupts should be introduced after students are comfortable with normal Digital Input and Control blocks.


13. DAC Analog Output

The final group contains the DAC blocks.

DAC means: Digital-to-Analog Converter

This is different from ADC:

  • ADC → Analog Input → Digital Value
  • DAC → Digital Value → Analog Output

This distinction is worth reinforcing.


Setup DAC

The corresponding setup can generate:

dac25 = machine.DAC(machine.Pin(25))

This creates the DAC output associated with the selected DAC-capable pin.


DAC Output Value

The visible example uses: 0

dac25.write(0)

The numerical value supplied to the block determines the value sent through the DAC operation.


Digital vs. ADC vs. PWM vs. DAC

Students will benefit from seeing these concepts together.

TypeDirectionMain Idea
Digital InputComponent → D1 R32Read one of two digital states.
Digital OutputD1 R32 → ComponentSend HIGH or LOW.
ADCAnalog Signal → D1 R32Convert an analog input to a numerical reading.
PWMD1 R32 → ComponentGenerate a pulse-width-controlled output.
DACD1 R32 → ComponentGenerate an analog output value.

ADC vs. DAC

These two names are easy for beginners to confuse.

ADC

  • Analog → Digital
  • Sensor → ADC → Program

DAC

  • Digital → Analog
  • Program → DAC → Output

An easy memory rule is:

ADC brings analog information INTO the program. DAC sends analog output FROM the program.


Quick Guide for Students

  • Do I only need ON/OFF? Think Digital.
  • Do I want to read a button or digital sensor? Use Digital Input.
  • Do I want to turn a digital output ON or OFF? Use Digital Output.
  • Do I need to read a changing analog sensor signal? Use ADC / Analog Input.
  • Do I need to configure the ADC input characteristics? Use the Attenuation setting.
  • Do I need to change ADC conversion resolution? Use 9-bit, 10-bit, 11-bit, 12-bit or 16-bit resolution.
  • Do I need a pulse-controlled output? Use PWM.
  • Do I need the program to react to a pin transition?  Use an Interrupt.
  • Do I need analog output through a DAC-capable pin? Use DAC.

Quick Reference

GroupMain Idea
HIGH / LOWDigital logical states.
Digital SetupConfigure a pin for digital operation.
Digital OutputWrite HIGH or LOW.
Digital InputRead a digital state.
ADC SetupConfigure an analog input.
ADC AttenuationSelect 11DB, 6DB, 2.5DB, or 0DB through the corresponding block choices.
ADC ResolutionSelect 16, 12, 11, 10, or 9-bit conversion resolution.
ADC ReadObtain an analog reading.
PWM SetupConfigure a PWM output.
PWM DutySet its duty value.
PWM FrequencySet its frequency.
InterruptReact to RISING, FALLING, or both transitions.
DAC SetupConfigure a DAC output.
DAC ValueWrite an analog-output value.