Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to DS18B20 sensor #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions examples/06.Sensors/DS18B20/temp18b20.pde
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
/* -----------------------------------------------------------------------
/* -----------------------------------------------------------------------
Pinguino example to read ds18b20 1wire temperature sensor
Result is sent on usb-serial bus and can be read with index.php
author Régis Blanchot
first release 14/09/2010
last update 10/06/2011
IDE Pinguino > b9.5
-----------------------------------------------------------------------
-----------------------------------------------------------------------
DS18B20 wiring
-----------------------------------------------------------------------
-----------------------------------------------------------------------
pin 1: GND
pin 2: DQ (Data in/out) must be connected to the PIC
pin 3: VDD (+5V)
NB : 1-wire bus (DQ line) must have 4K7 pull-up resistor (connected to +5V)
-----------------------------------------------------------------------
-----------------------------------------------------------------------
Data's are sent to /dev/ttyACM0
Make sure you have persmission on it : sudo chmod 777 /dev/ttyACM0
Maybe you will have to add your user name to the dialup group
----------------------------------------------------------------------*/

#define ONEWIREBUS 14 // DQ line
#define ONEWIREBUS 2
#define RES_12BIT

char temp_sign = 0;
u16 ifar;
u8 ffar;

void setup()
{
}

}
void loop()
{
TEMPERATURE t;

if (DS18B20.read(ONEWIREBUS, SKIPROM, RES12BIT, &t))
{
if (t.sign) CDC.printf("-");
CDC.printf("%d.%d°C \r", t.integer, t.fraction);
TEMPERATURE t;
if (DS18B20.read(ONEWIREBUS, SKIPROM, &t))
{

temp_sign = t.sign ? '-' : '+';

ifar = t.integer * 100;
ifar += t.fraction;
ifar = (((long)ifar * 9) / 5) + 3200;
//ifar = ((ifar * 1.8) + 3200);
ffar = ifar % 100;
ifar /= 100;

CDC.printf("Temp: %c%2d.%02d C || %c%3d.%02d F\r\n", temp_sign, t.integer, t.fraction, temp_sign, ifar,ffar);

}
delay(1000);
}
}


6 changes: 3 additions & 3 deletions p8/include/pinguino/libraries/IRremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void IRsend_mark(u16 time)

// while () {} needs much less time than for (;;) {}
// for loop without NOPs : ~ 1,3 ms (889 iterations on 18f26j50)
// while loop without NOPs: ~ 712 �s (889 Iterations on 18f26j50)
// while loop without NOPs: ~ 712 µs (889 Iterations on 18f26j50)
while (i) {
_1us_
i--;
Expand Down Expand Up @@ -364,9 +364,9 @@ void IRrecv_enableIRIn(u8 recvpin)

// Timer3 is on 16 bits, prescaler 1, based on external crystal Frequency
#if defined(__18f25k50) || defined(__18f45k50)
T3CON = T3_OFF | T3_16BIT | T3_SYNC_EXT_OFF | T3_SOSC_OFF | T3_PS_1_1 | T3_RUN_FROM_OSC;
T3CON = T3_OFF | T3_16BIT | T3_SYNC_EXT_OFF | T3_SOSC_OFF | T3_PS_1_1 | T3_SOURCE_FOSC;
#else
T3CON = T3_OFF | T3_16BIT | T3_SYNC_EXT_OFF | T3_OSC_OFF | T3_PS_1_1 | T3_RUN_FROM_OSC;
T3CON = T3_OFF | T3_16BIT | T3_SYNC_EXT_OFF | T3_OSC_OFF | T3_PS_1_1 | T3_SOURCE_FOSC;
#endif

// nb cycles for 50us
Expand Down