Take your device control to the next level with a programmable I/O 1-Wire switch - the easy way to remotely switch and sense devices
A
A
Hardware Overview
How does it work?
1-Wire Switch Click is based on the DS2413, a dual-channel addressable switch from Analog Devices. The DS2413 combines two programmable I/O pins and a fully featured 1-Wire interface in a single package, ensuring that PIO output changes occur error-free. The PIO outputs are configured as open-drain, operate at up to 28V (provide a high level of fault tolerance in the end application), and have an ON-resistance of 20Ω maximum. By monitoring the voltage at its programmable I/O pins, the DS2413 lets you read back the state of the load, in this case, the state of the button, which in this configuration is in the role of input, while the output state is visually detected through the red LED marked with OUT. The DS2413's power is supplied parasitically from the 1-Wire bus,
a system with a single bus controller and one or more peripherals. With that in mind, this Click board™ has one additional unpopulated header, which enables the connection of other external 1-Wire devices, thus forming a line with several peripherals on one controller. The DS2413 also has a 64-bit long registration number that guarantees unique identification. This number addresses the device in a multidrop 1-Wire network environment, where multiple devices reside on a common 1-Wire bus and operate independently. As mentioned, the 1-Wire Switch Click communicates with MCU using the 1-Wire interface that, by definition, requires only one data line (and ground) for communication with MCU. The 1-Wire communication line is routed to the SMD jumper
labeled as I/O SEL, which allows routing of the 1-Wire communication either to the GP0 pin or the GP1 pin of the mikroBUS™ socket. These pins are labeled, respectively, the same as the SMD jumper positions, making the selection of the desired pin simple and straightforward. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.
Features overview
Development board
Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an
ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the
first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.
Microcontroller Overview
MCU Card / MCU
Architecture
AVR
MCU Memory (KB)
32
Silicon Vendor
Microchip
Pin count
28
RAM (Bytes)
2048
You complete me!
Accessories
Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Schematic
Step by step
Project assembly
Track your results in real time
Application Output
After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.
After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.
Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.
Software Support
Library Description
This library contains API for 1-Wire Switch Click driver.
Key functions:
c1wireswitch_set_pio_state
1-Wire Switch write specific programmable I/O state function.c1wireswitch_get_pio_state
1-Wire Switch read specific programmable I/O state function.c1wireswitch_get_pio_latch_state
1-Wire Switch read programmable I/O latch state function.
Open Source
Code example
This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.
/*!
* @file main.c
* @brief 1-Wire Switch Click Example.
*
* # Description
* This library contains API for 1-Wire Switch Click driver.
* The library initializes and defines the 1-Wire bus drivers to
* write and read data for state programmable I/O,
* as well as the default configuration.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and performs default configuration and sets
* the PIO A to OFF and PIO B to ON state.
*
* ## Application Task
* This example demonstrates the use of the 1-Wire Switch Click board by changing the PIO A state,
* which is controlling the LED, every time the state of PIO B changes.
* Change on the PIO B happens when the button is pushed.
*
* @author Stefan Ilic
*
*/
#include "board.h"
#include "log.h"
#include "c1wireswitch.h"
static c1wireswitch_t c1wireswitch;
static log_t logger;
static uint8_t state = 0;
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
c1wireswitch_cfg_t c1wireswitch_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
c1wireswitch_cfg_setup( &c1wireswitch_cfg );
C1WIRESWITCH_MAP_MIKROBUS( c1wireswitch_cfg, MIKROBUS_1 );
if ( ONE_WIRE_ERROR == c1wireswitch_init( &c1wireswitch, &c1wireswitch_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( C1WIRESWITCH_ERROR == c1wireswitch_default_cfg ( &c1wireswitch ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
c1wireswitch_set_pio_state( &c1wireswitch, C1WIRESWITCH_PIOA_OFF, C1WIRESWITCH_PIOB_ON );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
uint8_t pio_a = 0;
uint8_t pio_b = 0;
c1wireswitch_get_pio_state( &c1wireswitch, &pio_a, &pio_b );
if ( pio_b == C1WIRESWITCH_PIOB_OFF )
{
if ( state == 0 )
{
c1wireswitch_set_pio_state( &c1wireswitch, C1WIRESWITCH_PIOA_ON, C1WIRESWITCH_PIOB_ON );
log_printf( &logger, " Button is pressed, LED is ON. \r\n " );
state = 1;
}
else
{
c1wireswitch_set_pio_state( &c1wireswitch, C1WIRESWITCH_PIOA_OFF, C1WIRESWITCH_PIOB_ON );
log_printf( &logger, " Button is pressed, LED is OFF. \r\n " );
state = 0;
}
Delay_ms( 100 );
}
Delay_ms( 100 );
}
void main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
}
// ------------------------------------------------------------------------ END