Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for 1wire examples
25-12-2011, 04:21 PM,
#1
Looking for 1wire examples
I am looking for examples for pinguino 1wire commands. The function and example on the web site is not very useful or clear.
Does not have the syntax or output section.

I am trying to put together a manual but I need to understand things first.
Reply
25-12-2011, 04:58 PM,
#2
RE: Looking for 1wire examples
You can check the /p32/include/pinguino/libraries/1wire.c file and 18b20.c file in the same folder.
1wire.c is the low level library to communicate with 1wire devices ( reset, write and read state of the data line with the appropriate timing ).
18b20.c is an example with a temperature sensor with the protocol common for most of the 1 wire devices ( MatchROM etc... ). It can be adapted for a lot of 1wire devices.
If you need more help on a specific point, post here the question.

Jean-Pierre

(25-12-2011, 04:21 PM)magicman Wrote: I am looking for examples for pinguino 1wire commands. The function and example on the web site is not very useful or clear.
Does not have the syntax or output section.

I am trying to put together a manual but I need to understand things first.

Reply
25-12-2011, 08:42 PM,
#3
RE: Looking for 1wire examples
magicman,

if you are interested in using one-wire temperature sensors, then you will find an example for use with the DS18B20 at /examples/6.Sensors/DS18B20/temp18b20.pde. This example assumes that there is only a single DS18B20 on the onewirebus, but is a good starting point for confirming the operation of a single DS18B20 sensor. The only change you may want to make for use with a PIC32 Pinguino OTG is to change the line:-

Code:
#define ONEWIREBUS      14

as Pinguino Pin 14 is shared with one of the analogue input/outputs. I would suggest changing it to:-

Code:
#define ONEWIREBUS      3

This will mean that you will connect pin 2 (DQ) of the DS 18B20 to Pinguino pin D3. I have found that using the 3V3 supply for VDD with a 4k7 pull up resistor to the 3V3 line works with no apparent problems with a single sensor. Most of the examples of using a DS18B20 available on the internet seem to be based on Arduinos, which use a 5V supply, but the Pinguino's the 3V3 supply also falls within the supply voltage range of the DS18B20.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
26-12-2011, 02:44 AM,
#4
RE: Looking for 1wire examples
Thanks for your suggestions.

In examples I see a lot of u8 refferences. But I do not see where this is defined or understand clearly what u8 means etc. Does u8 mean it is for 8 bit micros? Don't quite get it yet or how it is used and processed by the pinguino language.

u8 OneWireReset(u8);
u8 OneWireReadBit(u8);
void OneWireWriteBit(u8, u8);
u8 OneWireReadByte(u8);
void OneWireWriteByte(u8, u8);

static void OneWireLow(u8 DQpin)
u8 OneWireReset(u8 DQpin)
{
u8 presence;


Reply
26-12-2011, 10:56 AM,
#5
RE: Looking for 1wire examples
Hi magicman,

No, the u8 references do not mean that it is for 8 bit micros, they are data types which have been defined elsewhere (see //p32/include/pinguino/core/typedef.h or //p32/include/pinguino/basics/typedef.h depending on which release you are using) as Pinguino uses some additional data types and/or abbreviation for data types over and above those defined in standard C. In this instance

Code:
typedef unsigned char            u8;

The line you refer to I think come from file //p32/include/pinguino/libraries/1wire.c - in this instance I think :-

Code:
u8 OneWireReset(u8);

is what is referred to as a "forward definition" of a function (I am not sure if that is correct terminology), but in essence is saying the function OneWireReset will return a single u8 value (the u8 at the start of the line) and is expecting to be passed a single u8 value (the u8 in brackets ( ) ).

Assuming that you are looking at file //p32/include/pinguino/libraries/1wire.c (hint - it helps people to help you if you give full details of the file that you are quoting lines from), further down the file you will find the full function definition :-

Code:
    u8 OneWireReset(u8 DQpin)
    {
        u8 presence;

        OneWireLow(DQpin);            // pull DQ line low
        Delayus(480);                // leave it low for min. 480us
        OneWireHigh(DQpin);            // allow line to return high
        Delayus(60);                // takes 15 to 60 us
        presence = digitalread(DQpin);    // get presence signal
        Delayus(420);                // wait for end of timeslot (960-480-60=420)
        return (presence);
    }

The first line again gives the type definitions of the parameters/values to be returned by and passed to the function and also that the value being passed to the function is stored in variable "DQpin" within the function. The next line defines variable "presence" to by of type u8. The final line within the function says that the value in variable "presence" is returned to the line calling the function. This is, I believe, standard C functionality - I say "I believe" as I too am learning as I go along.

There are numerous reference documents for C on line. I tend to refer to The GNU C Reference Manual as Pinguino uses the GCC compiler for 32bit Pinguinos, such as the PIC 32 Pinguino OTG that you are using.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
26-12-2011, 11:11 AM,
#6
RE: Looking for 1wire examples
Thanks MF01. Appreciate you replying and helping me out.
Best regards
Bill
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)