TinyCircuits Forum

TinyCircuits Products => Wirelings => Topic started by: lcpalm on September 16, 2022, 10:17:03 PM

Title: Output Differs using Wireling Analog than ProtoTermimalShield on TinyZero?
Post by: lcpalm on September 16, 2022, 10:17:03 PM
I have a TinyZero circuit that works as expected when connected using Proto Terminal Blocks shield, or using an Arduino UNO.
But it does not work when connected in the same way with Wirelings....! I'm trying to use GND, 3v3, and INT wires, along with an external pull-up resistor to get analog voltage values off my sensor.

Does Wireling have some internal processing that prohibits using this analog input in this way? can I turn that off? or am I doing something wrong?

My code:
Code: [Select]
// 2022-09-15

#include <Wire.h>
#include <Wireling.h>

// boilerplate code to make serial monitor work with either arduino uno or tinycircuit's tinyzero
#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB

#define irdPin A0        // Corresponds to PORT# of Wireling used; or A0 of TerminalBlocks or Arduino UNO
int readValue = 0;       // the IR sensor value, analog

void setup() {

  // Start with a 3s delay, lighting external green LED for 3s.
  pinMode(LED_BUILTIN, OUTPUT);     
  digitalWrite(LED_BUILTIN, HIGH);   
  digitalWrite(LED_BUILTIN, LOW);   


  pinMode(irdPin, INPUT);


void loop() {
  readValue = analogRead(irdPin);

  SerialMonitorInterface.print("IRD pin read value: ");



I took a Wireling cable and stripped the ends of the GND, 3V3, and INT (analog) and soldered them to wires to plug into a breadboard for testing.

On TerminalBlocks: I connect GND, VCC, and A0 to my protoboard.
On Wireling: I connect GND, 3V3, and INT from port 0 to my protoboard (equivalent).

The board has a couple of diodes and resistors as follows:
1. IR-Emitter diode with external current-limiting resistor: Just emits IR light:
VCC --------- 220ohmResist -------(+)anode_IRE_cathode(-)--------- GND

2. IR-Detector diode with external pullup resistor, connected to A0 between the resistor and the IRD:

VCC -----10kResist ---/-----(+)anode_IRD_cathode(-)------------------GND

When IRD is active (detects IR light), voltage on analog input A0 should be low voltage,
 When IRD is inactive (detects no IR light), voltage on A0 should be a higher voltage.

Works perfectly with TerminalBlocks shield on TinyZero, or with Arduino UNO:
 Low ~53            when IRD gets IR light
High ~700-800  when IR light blocked (using UNO 3.3V, High is ~500; that's fine)

But with Wireling shield, same connections: Not working!
Output is  ~1 or 2, or 3   when IRD gets IR light
and is also  ~1 or 2, or 3   when IR light blocked

I know that I can set an *internal* pull-up resistor on the analog input A0, but we don't want this -- we want to get an analog voltage value.
I found this earlier forum post about analog wireling use but it did not help here.  http://forum.tinycircuits.com/index.php?topic=2419.msg5307#msg5307

Datasheets for the  IRE and IRD diodes: https://www.sparkfun.com/products/retired/241

Thank you for any help!!
Title: Re: Output Differs using Wireling Analog than ProtoTermimalShield on TinyZero?
Post by: lennevia on September 19, 2022, 10:32:05 AM
Hi there,

Thanks for posting your example code and detailing your process so well!

It looks like you need to add Wireling.begin(); to your setup loop. This function is needed for all Wireling programs to put the power pin of the Wireling TinyShield and other Wilreling boards in the correct mode.

Let me know if you have any other questions!

Title: Re: Output Differs using Wireling Analog than ProtoTermimalShield on TinyZero?
Post by: lcpalm on September 20, 2022, 07:33:10 PM
Hi Réna,

Thank you so much! That was it. It works perfectly now.

Phew :)

May I ask, just to be clearer:
-- Can I leave out the line, #include <Wire.h> , in my code?
   (and I don't need to run Wire.begin(); in my setup?)
-- Can/should I include a line:
    Wireling.selectPort(0);   ? or in my case Wireling.selectPort(A0);  ?

As this example,

includes these lines:

Code: [Select]
#include <Wire.h>               // For I2C communication
#include <Wireling.h>           // For Interfacing with Wirelings

// and then in setup:


 // Enable & Power Wireling
 Wireling.selectPort(0); // This must match the port the Wireling is connected to
                          // on the Adapter board

I am not using I2C, so maybe better to leave out the #include <Wire.h>
But I'm not sure about why I do or do not need Wireling.selectPort(0) or (A0).

Thanks again,
Title: Re: Output Differs using Wireling Analog than ProtoTermimalShield on TinyZero?
Post by: lennevia on September 21, 2022, 03:07:56 PM

You should be able to leave out the #include <Wire.h> line and you won't need to select the ports since you just need to interface with the pin.

As long as no errors come up with those revisions and everything is working as expected, all should be well!