Author Topic: making a wheather station with LCD AND WEB interface  (Read 37993 times)

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #30 on: May 30, 2007, 01:56:47 PM »
Hi attila,

Thanks for the warning.

I was intending to put the AAG weather station on a pole above my roofline. I'll have to lookup protection as well. There may be info on the Dallas weather instrument forum. I guess those guys must have suffered similar problems.

regards
Grognut.

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #31 on: June 10, 2007, 01:09:35 AM »
Greetings to every body!


I have my new SBC65EC board two days ago, and since that I am not able to implement my code from SBC68EC to the new one.   I have no idea why.  :oops:  :? ???
According to the schematics the two board are identical, except the microcontroller. Is there any other differences between the two boards?

The main problem is the MSSP hardware does not work in SPI mode at all, and on the serial communication I have lots of corrupted characters, when I am accessing the web server, or just randomly.

The same code worked on SBC68EC without a problem, but not on SBC65EC.

Here is my code what I use for serial communication.
I have a sensor which transmits datas with 9 bits length and an LCD display which received serial data from the board (also with 9 bits9 to display all infos. All is working at 4800 bps speed.

Code: [Select]
/**
 * @brief           Interrupt driven Serial receive and transmit handler.
 * @file            serint.h
 * @author          <a href="www.modtronix.com">Modtronix Engineering</a>
 * @dependencies    -
 * @compiler        MPLAB C18 v2.10 or higher <br>
 *                  HITECH PICC-18 V8.35PL3 or higher
 * @ingroup         mod_sys_serint
 *
 *********************************************************************/

 /*********************************************************************
 * Software License Agreement
 *
 * The software supplied herewith is owned by Modtronix Engineering, and is
 * protected under applicable copyright laws. The software supplied herewith is
 * intended and supplied to you, the Company customer, for use solely and
 * exclusively on products manufactured by Modtronix Engineering. The code may
 * be modified and can be used free of charge for commercial and non commercial
 * applications. All rights are reserved. Any use in violation of the foregoing
 * restrictions may subject the user to criminal sanctions under applicable laws,
 * as well as to civil liability for the breach of the terms and conditions of this license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
 * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
 * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 **********************************************************************
 * File History
 *
 * 2005-09-01, David (DH):
 *    - Created documentation for existing code
 *********************************************************************/

#define THIS_IS_SERINT

#include "projdefs.h"
#include "serint.h"
#include "user\rs5c372.h"
#include "user\sdcard.h"

//Transmit buffer - contains data that has to be transmitted
static BYTE txBuf[SER_TXBUF_SIZE];
static BYTE idxTxbufGet;   //get index

//Receive buffer - contains received data
static BYTE rxBuf[SER_RXBUF_SIZE];
static BYTE idxSerRxbufGet;   //get index
static BYTE idxSerRxbufPut;   //put index

/**
 * Initialise the serint module. After calling this function, the serEnable() function must be
 * called to enable the serial port.
 */
void serInit(void)
{
    //Set transmit buffer to empty
    idxTxbufGet = 0;

    //Set receive buffer to empty
    idxSerRxbufGet = 0;
    idxSerRxbufPut = 0;

TRISCbits.TRISC6 = 1;
TRISCbits.TRISC7 = 1;

PORTCbits.RC6 = 1;
PORTCbits.RC7 = 1;

BAUDCON1bits.BRG16 = 0;      // 16-bit baud rate register enable bit
BAUDCON1bits.ABDEN = 0;      // Auto-Baud detect bit

    SPBRG1 = SPBRG_VAL;         // Set BAUD rate

TXSTA1bits.TX9 = 1; // 9 bit transmission enable bit
TXSTA1bits.TXEN = 1; // transmit enable bit
TXSTA1bits.SYNC = 0;      // EUSART mode select bit, 0 - async, 1 - sync
TXSTA1bits.SENDB = 0;      // send break character
TXSTA1bits.BRGH = 0;      // high baud rate select bit
TXSTA1bits.TX9D = 0;      // 9th bit of transmit data

RCSTA1bits.CREN = 1;      // Contious recive enable bit
RCSTA1bits.ADDEN = 1;      // Address detect enable bit
RCSTA1bits.RX9 = 1;


    //Interrupts
PIE1bits.RC1IE = 0;   //Disable USART Receive interrupt
PIE1bits.TX1IE = 0;   //Disable USART Transmit interrupt - is only enabled once a TXion is started

PIE3bits.RC2IE = 0;
PIE3bits.TX2IE = 0;

RCSTA1bits.SPEN = 1;
}


/**
 * Enables the serial port AND . Can only be called after serInit() has been called.
 */
void serEnable(void) {
    //Interrupts
   
PIE1bits.RC1IE = 0;   //Enable USART Receive interrupt
PIE1bits.TX1IE = 0;   //Disable USART Transmit interrupt - is only enabled once a TXion is started
}


/**
 * Receive ISR function
 */
void serRxIsr(void) {
    //Check for "overun error" (OERR bit 1) or "Framming Error" (FERR bit 2).

if (PIR1bits.RC1IF){

RCSTA1bits.ADDEN = 0;
    if (RCSTA1 & 0x06)
    {
        RCSTA1bits.CREN = 0;
        RCSTA1bits.CREN = 1;
    }

// if (RCSTA1bits.RX9D) idxSerRxbufPut = 0;

if (idxSerRxbufPut == 0) {
rxBuf[idxSerRxbufPut] = RCREG1;
idxSerRxbufPut++;
}
else {
if (idxSerRxbufPut < 3) {
rxBuf[idxSerRxbufPut] = RCREG1;
idxSerRxbufPut++;
}
else {
rxBuf[idxSerRxbufPut] = RCREG1;
Adc.Word_Val[ADC_T_OUT].v[0] = rxBuf[2];
Adc.Word_Val[ADC_T_OUT].v[1] = rxBuf[1];
idxSerRxbufPut = 0;
RCSTA1bits.ADDEN = 1;
}
}
}
}


/**
 * Transmit ISR function. This function should be called from the ISR if "(TXIF && TXIE)" evaluates to true.
 */
void serTxIsr(void)
{
    //Transmit next byte contained in transmit buffer. If whole buffer has been transmitted, disable
    //transmit interrupts.

//     PIE1_TXIE = 0;   //Disable USART Transmit interrupt when nothing more to TX
}

void serTask(void)
{
serRxIsr();

if (PIR1bits.TX1IF)
{
if (idxTxbufGet == 0)
{
TXSTA1bits.TX9D = 1;
TXREG1 = 0;
}
else
{
TXSTA1bits.TX9D = 0;

if (idxTxbufGet == 1)
TXREG1 = 0;
else
{
if (idxTxbufGet <= (T_Year + 2))
/* if (idxTxbufGet == (T_Year + 2)) TXREG = sdcError;
else */TXREG1 = DateTime[idxTxbufGet - 2];
else
TXREG1 = Adc.Byte[T_Year + 2 + 10 - idxTxbufGet];
}
}
idxTxbufGet++;
if (idxTxbufGet > T_Year + 12) idxTxbufGet = 0;
}
}


I am calling "serTask()" from the main loop, not from the ISR.
What is wrong with this code? Why the transmitted and the received characters and corrupted?  :?  :-( :? :-( :?

Thanks,
Attila.
« Last Edit: November 15, 2011, 05:05:45 PM by modtro2 »

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #32 on: September 24, 2007, 12:17:50 PM »
Hi Attila,

I've been looking at your website http://meteo.homelinux.net/ and I have a few questions.

I don't seem able to change the date on the Archivum page but you can change the Hány napot: value, which I deduce is days. Is this supposed to work?

I assume from one of your previous posts that you are using javascript to generate the graphs on the browser machine using wz_jsgraphics.js. This is what I want to do but could you be kind enough to explain (possible with example code) how you get the data for the graphs to the browser. I can't workout how to populate an array for the javascript.

Regarding you comments on lighning striKes, I believe the "Weather Toys" books has some info on this.

Regards
Grognut

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #33 on: October 02, 2007, 11:18:06 AM »
Hello Grognut!

To draw the graphs with wz_jsgraphics.js (http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm) is easy. At the beginning of the page I create an array and filling it up with datas. Then just draw the graph from the array. The source code is in the zip file (archive.htm, httpexec.c, httpexec.h). To fill up the array I have tried a "for loop", but somehow it does not works, it filled up the whole array with same values.

The date selection is not implemented yet on the webserver side. I have to write a simple search algorithm, but I had no time for that. Maybe later. You can select only, how many days you want to go back from now (1..30 days, yes you are right "Hány napot" means "How many days").

Thanks your comment on lightning, now I am using gas-discharge tubes, transient voltage suppressors zener diodes and good earth. So far I had no more trouble with lightning.


Best regards,
Attila.



grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #34 on: October 02, 2007, 11:54:51 AM »
Hello Attila,

Thank you for your information. It has helped me greatly.
I am currently sorting the code to interface to the Sd card. I'm using a software SPI interface which has my ADC's on and because of the 3.3->5v I've had to read the data on another line.
Because of other parts of the application (TCP/IP etc) I'm having to sort the ram usage. I've modified SK Pang's 1-wire routines and found that there is a 256 byte array in ram for CRC lookup. I've just moved this into the ROM.
Also for some reason the linker was leaving a 256 block unused. I just sorted this now (as I type) and should be trying the SD Card later this evening.
In terms of getting the data into the JS script the way you are doing it was one way I had considered. Another way was to use C to write a Jscript file into the server page eeprom as the data was logged. I think I'm going to use your method.
The way I'm organising my data in the SD card will be in order so if you know the date/time the first record you can calcutate the record position of the date/time that you want to display. This will save searches.

Thanks again. I'll post the url when it is running or at least part running.

Regards
Grognut

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #35 on: October 03, 2007, 09:20:12 AM »
Hi Grognut!

You are welcome, I am happy if you can use something from my code. Yes, post you url when it will be ready, pls, I am interested what you have done.

For SD-Card and ADC I am using the same SPI lines (hardware SPI). I have no problem with the level conversion (5V ADC and 3.3V SD works fine from same lines).

As you can see, I am using 1-wire network as well, but the routines not implemented on web-server side, I am using one more PIC to handle 1-wire and sending data on RS-485 network (SK Pang's board contains too many things).

With date/time organization my problem is: what is you loose power, then you will miss to store some data. I this case you cannot calculate the required position later.

Best regards,
Attila.


grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #36 on: October 04, 2007, 01:55:09 PM »
Hi Attila,

I see your point about calculating the position of a record after loss of power. I hadn't thought of that.
After looking at your code I think it would take me a long time to write something similar.
I've also implemented consensus averaging for wind direction. I'll post it soon. At the moment it has stopped working properly since I added the SD card routines.
I have the AAG weather station. It's still inside but some time I'll have to climb on the roof and put it up. Then I'll have to put lightning protection on.

Regards
Grognut.

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #37 on: October 23, 2007, 03:59:50 PM »
Hi Attila,

I've have the logging working now. I haven't finished what I need to do so it's a bit scruffy.
The web page is at http://weather.dnsdojo.org:8080/
Some pages are removed because they are not secure yet.
I have another thought in searching records. If the address of the record is calculated from the unix time stamp. If there was a power fail at any time then the records would still be in the right order and position but some would not contain data. If the record is check summed or crc'ed then an invalid record can be detected.
I've just created a post regarding greater than 64k of web pages. The graphing code seems to take up a large proportion of it and when I add some diagnostics pages it becomes greater than 64k. Are you using the sd flash to store web pages? If so how easy is it to modifiy the code. I fitted a 128K eerpom but I don't think the file system supports it.
Regards
Grognut.

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #38 on: October 31, 2007, 10:32:24 AM »
Hello Grognut!

Your graphs looks nice!  :-).

Search algorithm: as I can understand you, you will calculate form the date and time a number for offset(like Julian date) and will use that number to index the records? It is a good idea, howewer you will lose some SD-Card space. Right now, at each power on (or reprogramming) I am doing a search for the end.

Web pages: If you are using SD-Card for data logging, then it is easy to use it to store web pages as well. I have an old 128MB card which is splited into two parts, one for web pages and config data, one for data logging.You need to modify the routines in fsee.c and fsee.h to read from SD-Card instead of EEPROM. Basically, I am just replaced the reads and writes from EEPROM to SD. (you have to modify some function in helpers.c and ftp.c as well). However after my modification, I cannot use Modtronix software to upload web-pages, but simple ftp program works fine. My source code is attached below. (I am not really good in coding, basically this is my first program in C)

Is the SD-Card works fine for you?

I have a question: do you have a rain gauge from aagelectronica? Mine started to work strangely, when the temperature drops below 9 or 8 °C, it counts continuously. Strange.

Best regards,
Attila.

« Last Edit: October 31, 2007, 10:43:07 AM by attila »

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #39 on: October 31, 2007, 02:56:38 PM »
Hi Attila,

Thanks for your comments. They're appreciated.

I want to spent more time making the whole page more attractive but I've run out of web page storage.
I'm using a 512Mb sd flash card and each of my records are 128 bytes I will be storing domestic heating temeratures, fridge and freezer temps as well as environmental values.

Using this sd card gives 4 million minutes of logging (about 7 years) so I'm not worried about losing a few records and their space. Also using the julian date means there will be no need to search for the last record when starting. I use a mini Sd card and soldered the adaptor in so I can change the card at any time. (I'll have to equate the current julian date with the starting point in the new card.)
I've have looked at your code, (it looks good to me) and the problem I have is getting a 512 byte buffer. I use 128 for my data record, 128 bytes for a tcp comms buffer, and another 128 for reading and writing to the sd card so there's now a shortage of ram. I'm still looking for more ram to reclaim but at the moment I can get any more back.

To overcome the issue of writing 512 bytes to the SD card I buffer data in the FRAM. I might try this with the web pages but I think it will slow things down to much.

I'm not using the aag rain gauge currently but I will by the adaptor board some time to fit in the cheap rain gauge I bought recently. It's somewhat ironic that the second day I had the rain gauge I recorded 96mm of rain in less than 16hrs. There was major flooding in my home town and other areas nearby.
One possibility for yours counting continuously is condensation or possibly a bad solder joint. Temperature affects bad joints dramatically.

It would be interesting to know how any others who have contributed to this thread are getting on!!! I feel like we've taken over this thread. :oops:

Best regards
Grognut

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #40 on: November 02, 2007, 10:01:54 AM »
Hello!

Yes, it would be good to know and see, how the others progressed!

Can I ask you which board are you using? With SBC65 I still have 559 bytes available in RAM (3376 used, 3935 total). You can use one RAM buffer for data read/write and web-page read/write. Sorry to ask, but how are you using 128 bytes buffer for SD writing? According to SD-Card specifications in SPI mode the only valid block length for write is 512 bytes.

1-wire: I found an interesting site: http://home.hetnet.nl/~thomas_7/1Wire/1-WireIOPort.html
http://home.hetnet.nl/~thomas_7/1Wire/1wire_isolating.html

Regards
Attila.
« Last Edit: November 02, 2007, 10:06:13 AM by attila »

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #41 on: November 02, 2007, 11:54:43 AM »
Hi Attila,
I'm using the SBC65.
If you have plenty of ram left I'll have to start digging through the map file to see where it's gone. It could be the linker script. I changed it slightly because I was having problems finding ram. I'm using the 306 server code I don't know if this uses more ram or not.
Another thing I find is that I'm up to 64K of code which seems excessive and when I go over the 64k boundary it becomes unreliable.


I'm using the fram to buffer 512 bytes of data and grabbing it in 128 byte blocks and writing to the SD card in 4 blocks. I thing it makes it slow because of the 2 serial accesses.

Best regards
Grognut

grognut

  • Hero Member
  • *****
  • Posts: 55
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #42 on: January 09, 2008, 04:50:45 AM »
Hi Attila,

I've got the webserver using the SD card to serve pages. Thankyou for your help.

I only implement the file system part and I can still use the modtronix loader to upload web pages which is kinda handy.
I was still short of ram to be able to have a file system buffer and a logged data buffer. BUT as I write this i realise that I don't need 2 x 512 but 512 and enough ram for the log buffer.

Now I need to get my humidity sensor working and improve the page look.

Cheers
Grognut

Danchoi-955

  • Sr. Member
  • ****
  • Posts: 26
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #43 on: January 10, 2008, 12:43:58 PM »
The FSEE file system only allows for maximum of 16Mbyte addressing due to the 24-bit address space used in the FAT.  How have you guys over come this if you are using SD cards that are over 16Mbyte?

attila

  • Full Member
  • ***
  • Posts: 21
    • View Profile
Re: making a wheather station with LCD AND WEB interface
« Reply #44 on: January 13, 2008, 04:01:54 AM »
Hello Grognut!

I am happy, if my help was useful for you  :-). In the meantime, I am wrote the search algorithm to find any date in the logged data.

Danchoi-995: I am addressing SD Card directly for data logging, and using FSEE only for web page storage.

Best regards,
Attila.