Output Differs using Wireling Analog than ProtoTermimalShield on TinyZero?

lcpalm · 4 · 1421

lcpalm

  • Full Member
  • ***
    • Posts: 14
    • View Profile
Hi,
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]
//TerminalBlocksVsWireling
// 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
#endif

#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() {
  SerialMonitorInterface.begin(9600);

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

  SerialMonitorInterface.println("");
  SerialMonitorInterface.println("TerminalBlocksVsWireling");

  pinMode(irdPin, INPUT);

}

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

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

  delay(500);

}

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
                                 /
                              A0

So,
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.

Results:
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!!


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 384
    • View Profile
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!

Cheers,
Réna


lcpalm

  • Full Member
  • ***
    • Posts: 14
    • View Profile
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,
https://learn.tinycircuits.com/Wirelings/Hall-Effect_Wireling_Tutorial/

includes these lines:

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

// and then in setup:

Wire.begin();

 // Enable & Power Wireling
 Wireling.begin();
 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,
Linda
« Last Edit: September 20, 2022, 07:38:06 PM by lcpalm »


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 384
    • View Profile
Linda,

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!

Cheers,
Réna


 

SMF spam blocked by CleanTalk