Author Topic: IR tx,photodiode:Interfacing with digispark  (Read 4380 times)

jaghvi

  • Newbie
  • *
  • Posts: 29
IR tx,photodiode:Interfacing with digispark
« on: July 29, 2013, 05:08:16 am »
I am trying to interface ir rx tx led pair with DS. The tx rx pair is working fine (analogread shows perfect readings using arduino) but on DS I get the readings using digiterm but they arent right.Moreover even if i disconnect my sensor ckt I still get the readings.
I encountered same problem when i hooked up lm35 temp sensor.I get readings despite I havent connected anything on PIN5.
this is the code

#include <DigiUSB.h>

void setup() {
  DigiUSB.begin();
  pinMode(0,INPUT);
}

void loop() {
  // print output
  DigiUSB.println("Waiting for input...");
  // get input
  int val=analogRead(0);
  DigiUSB.println(val);
  DigiUSB.delay(500);
}

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: IR tx,photodiode:Interfacing with digispark
« Reply #1 on: July 29, 2013, 12:12:06 pm »
The analog pin numbering can be confusing because the physical pin numbers don't match the logical pin numbers. And you have to use the logical pin numbers with the analogRead() and analogWrite() functions, but use the physical pin numbers when setting the mode.

The mappings are:
A0 <==> P5
A1 <==> P2
A2 <==> P4
A3 <==> P3

So if you change your code to use 'analogRead(5)', it should start giving more sane results.

However, if you look at the notes on the excellent pinout diagram done by semicolo, you might note that P5/A0 has weaker signal than the other pins (an internal Atmel thing). And since P3 and P4 are used for USB, you might want to use P2/A1 for your testing.

jaghvi

  • Newbie
  • *
  • Posts: 29
Re: IR tx,photodiode:Interfacing with digispark
« Reply #2 on: July 29, 2013, 11:05:46 pm »
pinMode(2,INPUT);//physically connected PIN 7 of IC
analogRead(1);


/everything working fine :)
http://digistump.com/wiki/digispark/tutorials/basics...this helped as well