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 0000000..3b647c4 Binary files /dev/null and b/FlammableGasSensor/docs/.3.tex.swp differ diff --git a/FlammableGasSensor/docs/4.tex b/FlammableGasSensor/docs/4.tex new file mode 100644 index 0000000..5f97dd8 --- /dev/null +++ b/FlammableGasSensor/docs/4.tex @@ -0,0 +1,73 @@ + +\documentclass[11pt]{article} +%Gummi|065|=) +\usepackage{graphicx} +\usepackage{caption} +\title{\textbf{Flammable Gas Sensor}} +\author{Steak Electronics} +\date{} +\begin{document} + +\maketitle + +\tableofcontents + +\section{Overview} +Shop needs a flammable gas sensor, for safety. +\section{Chip Hunting} +I'm looking at the following: + +\begin{itemize} +\item SGAS711 +\item 200K fixed resistor +\item 1M potentiometer +\item Arduino Nano (for speed) +\item Ample Power Supply They are recommending 7 Volts for the heater. So, one rated for 1A. +\item led notifiers + \item + +\end{itemize} + + +\subsection{Gas Sensor Tuning} +The flammable gas sensor has different sensitivities for different gases (see data sheet, Figure 8). I'm going to need to test for something specific, i.e. if the shop needs to watch out for acetone, I should test acetone. Of course, if enough of a flammable gas is in the air, it will set it off no matter what, but I should focus on what the danger is for calibrating. + +Based on the resistance chart, I'm going to use a fixed 200K and a 1M pot. Pots are to be avoided, but here we need to calibrate over time. For the response of the v divider, the sensor is not linear, but closer (though not quite) logarithmic. So what I will do, is have to use some math on the micro, and use the formula they give in the Datasheet, to get a logarithmic output that appears linear (figure 5). For my needs, it is good enough. + +\includegraphics[scale=0.8]{../pics/resistances.png} +\captionof{figure}{Application Note resistance table} + +\subsubsection{Fixed resistors} +If these sensors are consistent enough, possibly I could use fixed resistors later. +\subsubsection{Gas Sensor Power Usage} +Rated at 900mW for 7V, so about 150mA (128mA). I know from prior experience these things heat up, so we need plenty of power. + +\subsubsection{PCB Layout} +The gas sensor must be sideways, as there is excessive dust in the shop so, the holes will be on the side. I will do a 90 degree edge mount pcb. + +\subsection{Switcher} +STS1024S6V5 Seems like a fair option for now. Output is 6.5 volts which is enough. Will use a module. Need to make a footprint. + +\subsection{Enclosure} +We need a box that is tall enough to be a cube. Also want square, not rectangular. I plan to have the leds light from the back of the pcb. The pcb will be the top cover / front. The top cover / front will be the box, put on its side, so dust doesn't collect on the leds. Need a cube. + +\section{CAD Layout} +I found that Kicad step up in Freecad is helpful for making sure your board will fit the enclosure. A very helpful addition to an arsenal. Although I didn't test it until after rev 1. +\begin{center} +\includegraphics[scale=0.5]{../pics/kicadstepup1.jpg} +\captionof{figure}{Freecad has the ability to pull in boards from Kicad. Even without step file dependencies you can see how the PCB will fit a case} +\end{center} + + +\section{PCB Assembly} +Most of the board came out ok. Power section is routed right. I need to move the barrel plug further out of the board, so it fits with the case better. The one issue I overlooked +was the A6, and A7 pins, which have no digital circuitry behind them. So I have some pins that can't light up. I'll have to bodge wires in, or respin the board. Simple fix. Oversight on my part, that's all. I assumed +GPIO on all pins, but here are two analog pins that can't function as GPIO. +I'll use D7, and D8. Looks like I also missed the wire from VSenseOut of the Gas sensor to the board. So that will go to A6. + + + + + +\end{document} + diff --git a/FlammableGasSensor/resources/a6_a7_atmega328_no_digital_circuitry.php b/FlammableGasSensor/resources/a6_a7_atmega328_no_digital_circuitry.php new file mode 100644 index 0000000..f6b5c2d --- /dev/null +++ b/FlammableGasSensor/resources/a6_a7_atmega328_no_digital_circuitry.php @@ -0,0 +1,668 @@ + + + + + + + + + + + + + + + + + + + + + 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