From 4b8efc73b043b98b4978a5e4c5b7d44e9e0d3e83 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 4 Jun 2019 01:10:39 -0400 Subject: [PATCH] Ardu. --- .../arduino/gassensor_reva/gassensor_reva.ino | 169 +++++ FlammableGasSensor/docs/.3.tex.swp | Bin 0 -> 1024 bytes FlammableGasSensor/docs/4.tex | 73 ++ .../a6_a7_atmega328_no_digital_circuitry.php | 668 ++++++++++++++++++ 4 files changed, 910 insertions(+) create mode 100644 FlammableGasSensor/arduino/gassensor_reva/gassensor_reva.ino create mode 100644 FlammableGasSensor/docs/.3.tex.swp create mode 100644 FlammableGasSensor/docs/4.tex create mode 100644 FlammableGasSensor/resources/a6_a7_atmega328_no_digital_circuitry.php diff --git a/FlammableGasSensor/arduino/gassensor_reva/gassensor_reva.ino b/FlammableGasSensor/arduino/gassensor_reva/gassensor_reva.ino new file mode 100644 index 0000000..419c446 --- /dev/null +++ b/FlammableGasSensor/arduino/gassensor_reva/gassensor_reva.ino @@ -0,0 +1,169 @@ + + + +//currently 8 leds controllable +#define LED1 A0 +#define LED2 A1 +#define LED3 A2 +#define LED4 A3 +#define LED5 A4 +#define LED6 A5 +#define LED7 7 //A6, and A7 are ADC only. No GPIO. +#define LED8 8 + +#define Sensor A6 + +uint16_t gasVAL; + +void setup() { + // put your setup code here, to run once: +Serial.begin(9600); + +pinMode(LED1, OUTPUT); +pinMode(LED2, OUTPUT); +pinMode(LED3, OUTPUT); +pinMode(LED4, OUTPUT); +pinMode(LED5, OUTPUT); +pinMode(LED6, OUTPUT); +pinMode(LED7, OUTPUT); +pinMode(LED8, OUTPUT); + + +Startup(); + +} + +void loop() { + // put your main code here, to run repeatedly: + +gasVAL = analogRead(Sensor); +Serial.println(gasVAL); +lightLED(gasVAL); +delay(30); + +} + +void Startup (void){ + +digitalWrite(LED1,HIGH); +digitalWrite(LED2,HIGH); +digitalWrite(LED3,HIGH); +digitalWrite(LED4,HIGH); + +delay(1000); +digitalWrite(LED1,LOW); +digitalWrite(LED2,LOW); +digitalWrite(LED3,LOW); +digitalWrite(LED4,LOW); + +digitalWrite(LED5,HIGH); +digitalWrite(LED6,HIGH); +digitalWrite(LED7,HIGH); +digitalWrite(LED8,HIGH); + +delay(1000); +digitalWrite(LED5,LOW); +digitalWrite(LED6,LOW); +digitalWrite(LED7,LOW); +digitalWrite(LED8,LOW); + + +} + +void lightLED( uint16_t reading){ + +if (reading >= 750){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,HIGH); + digitalWrite(LED5,HIGH); + digitalWrite(LED6,HIGH); + digitalWrite(LED7,HIGH); + digitalWrite(LED8,HIGH); +} +else if (reading >= 700){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,HIGH); + digitalWrite(LED5,HIGH); + digitalWrite(LED6,HIGH); + digitalWrite(LED7,HIGH); + digitalWrite(LED8,LOW); +} +else if (reading >= 650){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,HIGH); + digitalWrite(LED5,HIGH); + digitalWrite(LED6,HIGH); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else if (reading >= 600){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,HIGH); + digitalWrite(LED5,HIGH); + digitalWrite(LED6,LOW); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else if (reading >= 550){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,HIGH); + digitalWrite(LED5,LOW); + digitalWrite(LED6,LOW); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else if (reading >= 500){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,LOW); + digitalWrite(LED5,LOW); + digitalWrite(LED6,LOW); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else if (reading >= 450){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,HIGH); + digitalWrite(LED3,LOW); + digitalWrite(LED4,LOW); + digitalWrite(LED5,LOW); + digitalWrite(LED6,LOW); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else if (reading >= 400){ + digitalWrite(LED1,HIGH); + digitalWrite(LED2,LOW); + digitalWrite(LED3,LOW); + digitalWrite(LED4,LOW); + digitalWrite(LED5,LOW); + digitalWrite(LED6,LOW); + digitalWrite(LED7,LOW); + digitalWrite(LED8,LOW); +} +else { + digitalWrite(LED1,HIGH); + digitalWrite(LED2,LOW); + digitalWrite(LED3,HIGH); + digitalWrite(LED4,LOW); + digitalWrite(LED5,HIGH); + digitalWrite(LED6,LOW); + digitalWrite(LED7,HIGH); + digitalWrite(LED8,LOW); +} + + + +} + diff --git a/FlammableGasSensor/docs/.3.tex.swp b/FlammableGasSensor/docs/.3.tex.swp new file mode 100644 index 0000000000000000000000000000000000000000..3b647c45a6df2d32bfd55043c4302d2ed4f14b1b GIT binary patch literal 1024 zcmYc?$V<%2S1{5u*E3;20>@1m7*bNpkVJ4ZiB+eck)NBY4^*x1l3JWyl3$>ooS%}a zpPG}JTvC*umzi9w?}}i@2NdOJ0cDEgjSLJe_1$t3b8{1ua#GzBi-S}1it~%~Q}Tg2 aO!P`pD{#AQRAw{;MneD|0- + + + + + + + + + + + + + + + + + + + + Arduino Nano - A6/A7 internal pull-up resistors + + + + + + + + + + + + + +
+
+
+
+
+ +
+
+
+
+ + +
+ +
+ + Print +
+ Go Down + +
+
+
+

+ Topic: Arduino Nano - A6/A7 internal pull-up resistors (Read 42291 times) + previous topic - next topic +

+
+
+
+
+
+

+ + dadaumpa +

+ +
+
+ +
+
Hello,

this is not mentioned anywhere in the documentation as far as I can see.

The question is: do the 2 extra analog pins (A6 and A7), which are found on the Arduino Nano and similar boards, have internal pull-ups?

I had a look at the ATmega datasheet, and it makes no mention of pull-ups for the two corresponding pins (ADC6 and ADC7, cfr. paragraph 1.1.9). It explicitly says, however, regarding the other pins (cfr. paragraphs 1.1.3, 1.1.4, 1.1.6) that they are "bi-directional I/O port with internal pull-up resistors".

So my guess is that there are no internal pull-up resistors for ADC6 and ADC7. Google also reports this explicitly mentioned on some AVR forum (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=89804&start=0).

Is this true? Otherwise I must conclude that my board is faulty :-)

If this is the case, BTW, it would be nice to add this information on the Arduino Nano page, in order to spare some possible headache to other hobbists...

Some background and context: I'm using the analog pins to read an array of buttons, similar to what described here: http://arduino.cc/forum/index.php/topic,20125.0.html.

To keep the circuitry at a minimum, I turn on the internal pull-up by using:

Code: [Select]
  pinMode(A6, INPUT);
  digitalWrite(A6, HIGH);


The trick worked so far with A0 and A5, but it doesn't with A6. I'm getting wildly fluctuating readings with no buttons pressed, which suggests the internal pull-up is either broken or... simply non-existant :-)

cheers,
Aldo



+
+
+
+
+
+
+
+
+
+
+ +
+
+

+ + cmiyc +

+ +
+
+ +
+
A6 and A7 are only inputs available to the mux in front of the ADC.  There is no digital hardware behind the pins.

Since the pull up is part of the digital latch, those two pins dont have pull ups (nor do they work as digital inputs.)

Not that it is affecting your code, keep in mind that pinMode() has no effect on analog pins.
+
+
+
+
+
+
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com
+
+
+
+
+
+ +
+
+

+ + dadaumpa +

+ +
+
+ +
+
Thanks for the explanation. Makes sense, just wasn't so obvious for a newbie like me :-)

Regarding pinMode(), that's curious. You mean it has no effect on A6/A7 because of their analog, input-only nature?

Because the page http://arduino.cc/en/Tutorial/AnalogInputPins actually uses pinMode() on an analog pin. Ok, that's obviously to set it as OUTPUT. INPUT should be redundant, since they are input by default. But I thought it was a good measure to set them to INPUT, just in case some code previously had set them in OUTPUT mode...

cheers,
Aldo
+
+
+
+
+
+
+
+
+
+
+ +
+
+

+ + Steph +

+ +
+
+ +
+
Regarding pinMode(), that's curious. You mean it has no effect on A6/A7 because of their analog, input-only nature?

Because the page http://arduino.cc/en/Tutorial/AnalogInputPins actually uses pinMode() on an analog pin. Ok, that's obviously to set it as OUTPUT. INPUT should be redundant, since they are input by default. But I thought it was a good measure to set them to INPUT, just in case some code previously had set them in OUTPUT mode...


The first six analog pins do have digital circuitry behind them, so pinMode and digitalWrite work just fine. It's just pins A6 and A7 on the surface mount '328 which are analog-only.

Cheers!
+
+
+
+
+
+
+
+
+
+
+ +
+
+

+ + cmiyc +

+ +
+
+ +
+

Regarding pinMode(), that's curious. You mean it has no effect on A6/A7 because of their analog, input-only nature?

pinMode() has no effect on analog inputs (A0-A7).

When analogRead() is called, the pin switches to an analog input regardless of what the pinMode was set as.


Because the page http://arduino.cc/en/Tutorial/AnalogInputPins actually uses pinMode() on an analog pin.

Yes, because the code in that example is showing how to use the analog pin into a digital pin.
+
+
+
+
+
+
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com
+
+
+
+
+
+ +
+
+

+ + 32teeth +

+ +
+
+ +
+
You can actually use A6 and A7 as 'digital' pins with a little bit of logic in your code
below is my craptastic  ]:D example

Code: [Select]
int pinStateA6 = 0;
int pinStateA7 = 0;

void setup()
{
}

void loop()
{
     pinStateA6 = analogRead(A6) > 100 ? 0 : 1;
     pinStateA7 = analogRead(A7) > 100 ? 0 : 1;
}
+
+
+
+
+
+
+
+
+
+
+ +
+
+

+ + tentoes +

+ +
+
+ +
+
pinMode can be used on A0-A5 to turn the internal pull-up resistor on or off.

    pinMode(A0, INPUT_PULLUP);  //on
    pinMode(A0, INPUT);  //off


+
+
+
+
+
+
+
+
+
+
+ +
+
+

+ + DrAzzy +

+ +
+
+
+
+ +
+ +
+ #7 +
+
+ Aug 03, 2015, 07:03 pm + Last Edit: Aug 03, 2015, 07:08 pm by DrAzzy +
+
+
+
+
Sigh....

Analog pins A0~A5 are normal pins. You can refer to them as pins 14-19 as well, and they can be used normally as digital pins.

Analog pins A6 and A7 are weird. They can *only* be used for analogRead() - there aren't any registers to write to for them like there are for other pins. I get the impression they were an afterthought (maybe the DIP package was released first, then they're like "hey we have some extra pins on TQFP32, let's connect them to the unused channels on the ADC mux")...

The next iteration of the x8 series (x8PB - only available up to 16k so far though) gives them proper treatment, putting them on a new port with those two pins, plus two pins that used to be a second set of power and ground pins, to make a 4 bit port.
+
+
+
+
+
+
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy
+
+
+
+
+
+
+
+ +
+ + Print +
+ Go Up + +
+
+ +
+
 
+
+ +
+
+
+
+
+
+ + +
+
+ +
+ + + + + + + + + + + + + + + + \ No newline at end of file