Shop OBEX P1 Docs P2 Docs Learn Events
Propeller zone monitor system(zms) — Parallax Forums

Propeller zone monitor system(zms)

In my other threads I did the test code for the DS1302, ADC0831, and CM2302. After verifying that the code works, I created a prototype concept, which the program below uses.

The prototype uses a breadboard that holds the FLiP module, WX module, DS1302, ADC0831, and CM2302. On a separate piece of stiff cardboard, I have two li-ion batteries connected in series(8V), voltage divider breakout, and a voltage regulator, which gets connected to the breadbord.

Now I can take the contraption to a specific location, and via a web browser I can get the temp, humidity, voltage, and set the RTC using the internet time. I guess I can say that this proof of concept works as expected.

The hard part is to get this contraption to do some data logging. I do not want to use an SD, takes up to much room on the breadboard, and the code to run it is way to big. Does anybody know if there is way to use the memory on the WX module for storing the data in a csv file. Or is there another easy method of doing data storage that I am not aware of.

I also thought about using the largest EEPROM I could find, placing it on the breadboard, and using that to hold the CSV file information. This I am not sure about. I would like to use the html program to access the csv file and download it to the device that I am running the html program on. Anybody have any other ideas?

Ray

mobTherm.c
/*
  mobTherm.c
  September 17, 2018
  Mobile thermometer project. Use CM2302, DS1302, and ADC0831.
*/
#include "simpletools.h"
#include "wifi.h"
#include "dht22.h"

#define US_005 (80000000 / 1000000 * 5)

int event, id, handle;
int getFromPageId;
char cmdStr[64];
char *path;


/* CM2302 */
volatile float gtemp,ghumid;  // Decimal point precision.

/**********************/
/* ADC0831 */
volatile float gbatt;
int cs, clk, dataOut;

void init(int cspin, int clkpin, int dataOutpin)
{
  cs = cspin;
  high(cs);
  set_direction(cs,1);
  
  clk = clkpin;
  low(clk);
  set_direction(clk,1);
  
  dataOut = dataOutpin;
  set_direction(dataOut,0);
}

int readADC()
{
  int level = 0;
  
  low(cs);
  pause_ticks(US_005);
  level = 0;
  
  for(int i = 0; i < 9; i++)
  {
    high(clk);
    pause_ticks(US_005);
    low(clk);
    pause_ticks(US_005);
    level = (level << 1) | get_state(dataOut);
  }
  high(cs);
  return(level & 0xFF);   
}  
/**********************/

/* RTC */
/* Using pins 17,18,19 with the FLiP module.*/
#define ds1302cs 19
#define ds1302sclk 18
#define ds1302io 17

#define dsSec 0x80
#define dsMin 0x82
#define dsHour 0x84

#define dsDate 0x86
#define dsMon 0x88
#define dsDay 0x8A
#define dsYear 0x8C

#define dsWpa 0x8E
#define dsTca 0x90

volatile int seconds,minutes,hours,date,month,day,year,prevSec;
int day2,month2,year2;
int hour2,minutes2,seconds2;


int readDs1302(int myreg)
{
  int readreg = myreg + 1;
  high(ds1302cs);
  shift_out(ds1302io, ds1302sclk, LSBFIRST, 8, readreg);
  int result = shift_in(ds1302io, ds1302sclk, LSBPRE, 8);
  low(ds1302cs);
  return result;
}

void writeDs1302(int myreg, int value)
{
  high(ds1302cs);
  shift_out(ds1302io, ds1302sclk, LSBFIRST, 8, myreg);
  shift_out(ds1302io, ds1302sclk, LSBFIRST, 8, value);
  low(ds1302cs);
}

static int bcdToD(unsigned int byte, unsigned int mask)
{
  unsigned int b1, b2;
  byte &= mask;
  b1 = byte & 0x0F;
  b2 = ((byte >> 4) & 0x0F) * 10;
  return b1 + b2;
}

static unsigned int dToBcd(unsigned int byte)
{
  return((byte / 10) << 4) + (byte % 10);
}

/**********************/

void get_Time();
void get_Date();

/**********************/
  
/* COG 1*/
void unit_CM2302();

/* COG 0*/
int main()
{
  // Add startup code here.
  cog_run(unit_CM2302, 128);
  pause(50);
  wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
  pause(50);
  getFromPageId = wifi_listen(HTTP, "/tpfm*");
 
  while(1)
  {
    // Add main loop code here.
    wifi_poll(&event, &id, &handle);
    if(event == 'G')
    {
      if(id == getFromPageId)
      {
        memset(cmdStr, 0, sizeof(cmdStr));
        sprint(cmdStr, "PATH:%d\r", handle);
        path = wifi_command(cmdStr);
        
        if(strstr(path, "/Temp1") !=0)
        {
          wifi_print(GET, handle, "%.2f", gtemp);
        }
        else if(strstr(path, "/Humid1") !=0)
        {
          wifi_print(GET, handle, "%.2f", ghumid);
        }
        else if(strstr(path, "Batt") !=0)
        {
          wifi_print(GET, handle, "%.2f", gbatt);
        }          
      }        
    }
    
    if(event == 'P')
    {
      memset(cmdStr, 0, sizeof(cmdStr));
      sprint(cmdStr, "PATH:%d\r", handle);
      path = wifi_command(cmdStr);
      
      if(strstr(path,"/datetime") !=0)
        {
          wifi_scan(POST, handle, "month%d%d%d%d%d%d",&month2,&day2,&year2,&hour2,&minutes2,&seconds2);
          int year1 = dToBcd(year2);
          writeDs1302(dsYear,year1);
          int month1 = dToBcd(month2);
          writeDs1302(dsMon,month1);
          int date1 = dToBcd(day2);
          writeDs1302(dsDate,date1);
          int hour1 = dToBcd(hour2);
          writeDs1302(dsHour,hour1);
          int minutes1 = dToBcd(minutes2);
          writeDs1302(dsMin,minutes1);
          int seconds1 = dToBcd(seconds2);
          writeDs1302(dsSec,seconds1);
          //dt_set(dt);
        }
    }

    //get_Date(); // This shows in terminal screen.   
    //get_Time(); // This shows in terminal screen.
    //pause(1000);
    pause(250);               
  }  
}
/**********************/

unit_CM2302()
{
  float temp,humid;
  init(22,21,20);  //22 - dopin, 21 - clkpin, 20 - cspin
  
  while(1)
  {
    dht22_read(16);
    pause(150);
    temp = dht22_getTemp(1);  // 1 - Fahrenheit
    temp = (temp*.10);
    gtemp = temp;
    
    humid = dht22_getHumidity();
    humid = (humid*.10);
    ghumid = humid;
    
    int level1 = readADC();
    gbatt = ((((level1*4010256)+5000)/1000000)*.01);
    
    pause(300);
  }    
}  

void get_Time()
{
  hours = readDs1302(dsHour);
  putHexLen(hours,2);
  putStr(":");
  minutes = readDs1302(dsMin);
  putHexLen(minutes,2);
  putStr(":");
  seconds = readDs1302(dsSec);
  putHexLen(seconds,2);
  putChar(NL);  // New line  
}

void get_Date()
{
  month = readDs1302(dsMon);
  putHexLen(month,2);
  putStr("/");
  day = readDs1302(dsDate);
  putHexLen(day,2);
  putStr("/");
  year = readDs1302(dsYear);
  putHexLen(year,2);
  putChar(NL);  // New line 
}

mobTherm.html
<!-- mobTherm.html -->
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      a{
        background-color:#637aad;
        color:white;
	   font-size:23px;
	   margin:5px;
	   width:100px;
	   height:55px;
	   cursor:pointer;
	   padding-top:4px;
	   padding-bottom:4px;
      }
      a:hover{background-color:white;color:navy;}
    </style>
  </head>

  <body bgcolor=3b5898>
     <br>
	<br>
	<br>
	<font face="Arial" size=3 color="cyan">
	<div>
	<a onclick="getFromMcu('Temp1')">Temp1</a>
	<a onclick="getFromMcu('Humid1')">Humid1</a>
	<a onclick="getFromMcu('Batt')">Battery</a>
	<br>
	<a onclick="datetimeBtn()">DateTime</a> -- Update RTC
	</div>
     <br>
     <br>
     <br>
	<font face="Arial" size=5 color="cyan">
     <p id = "value">Wating...</p>
	
   </body>

<script>
var getPathExt;

function useMcuReply(response)
{
	
	if(getPathExt == 'Batt1')
	{
	var val = document.getElementById("value");
	val.innerHTML = "Value: " + response;
	}
	else if(getPathExt == 'Temp1')
	{
	var val = document.getElementById("value");
	val.innerHTML = "Value: " + response;
	}
	else if(getPathExt == 'Humid1')
	{
	var val = document.getElementById("value");
	val.innerHTML = "Value: " + response;
	}
	else if(getPathExt == 'Batt')
	{
	var val = document.getElementById("value");
	val.innerHTML = "Value: " + response;
	}

}

function getFromMcu(pathExt)
{
	getPathExt = pathExt;
	httpGet("/tpfm/" + pathExt, useMcuReply);
}

function httpGet(path, callback)
{
	var req = new XMLHttpRequest();
	req.open("GET", path, true);
	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
			if(req.status == 200)
				callback(req.responseText);
			else
				callback("Wating...");
	}
	req.send(null);
}
function httpPost(path, param)
{
	var req = new XMLHttpRequest();
	req.open("POST", path, true);
	req.setRequestHeader("Content-type",
	"application/x-www-form-urlencoded");
	req.send(param);
}
function datetimeBtn()
{
	var dt = new Date();
	day = dt.getDate();
	
	var dt1 = new Date();
	month = dt1.getMonth();
	month = month +1;
	
	var dt2 = new Date();
	year = dt2.getFullYear();
	
	var dt3 = new Date();
	var hours = dt3.getHours();
	
	var dt4 = new Date();
	var minutes = dt4.getMinutes();
	
	var dt5 = new Date();
	var seconds = dt5.getSeconds();

	var send = "month=" + month + "day=" + day + "year=" + year + "hour=" + hours + "minutes=" + minutes + "seconds=" + seconds;
	httpPost("/tpfm/datetime",send);
}
</script>
</html>

«1

Comments

  • After giving the program a closer look, I noticed a few bugs, which I will take care of.

    I am now reconsidering the use of an SD, for the data logging part. I think I will just have make the SD socket fit somewhere. As for the SD code size, I will just have to make it fit, and work.


    I am considering adding a couple more sensors, but I seem to be having trouble finding something I can work with. I want to add a CO2 and Oxygen sensors. The ones that I have seen, I will probably have trouble finding some example C code to make them work. Anybody know of some decent sensors that work with the FLiP module?

    Ray
  • Rsadeika wrote: »
    I do not want to use an SD, takes up to much room on the breadboard...

    Would something like this SD card socket work, if you installed right-angle headers instead of the straight ones. Then you could plug it vertically into the breadboard to save space.

    https://www.parallax.com/product/32313


    ps. Any chance of sharing a photo of your breadboard setup? Always good to see pictures!

  • The photos show my version of an initial prototype setup. I have it laid out to have relatively easy access to all the parts.

    What will happen is the cardboard that is holding the batteries will get turned upside down and placed underneath the breadboard. Basically the unit will sit on the batteries. I will try to reduce the cardboard size to the size of the breadboard.

    Since I am using two li-ion batteries, in series, I will probably remove the voltage regulator, and in that section I will maybe try to fit an SD assembly. I think I have an SD breakout board that was meant to be plugged into the breadboard.

    My li-ion batteries are 3.6V 2600mAh, I still have to do some tests to see if they would be able to last a 24, maybe a 48 hour data logging session. Plus I plan to add a yellow LED as warning for a battery charge and with the addition of the CO2 and Oxygen sensors, that should be a substantial power draw, I would think.

    Ray
    1936 x 1296 - 698K
    1936 x 1296 - 701K
    1936 x 1296 - 698K
    1936 x 1296 - 678K
  • Gosh- I see what you mean now about breadboard space. The FLiP module really eats a good chunk, and you've got a lot going on already!

    Neat idea with the cardboard though. I like that, and will remember that in the future. It looks very practical for quick experiments and to get parts fixed in place that don't need to be on the breadboard.

    Thanks for posting the pics.

    I've never worked with oxygen sensing, but I'd have thought there must be some low-power way to sense, and if you can control the power to the sensor and only power it up once in a while, maybe that could extend the battery life. Just pondering aloud :)
  • I reconfigured my zms unit and I added an SD breakout gadget. Parallax used to sell these in an assembled unit, now it looks like it comes in a kit, to bad, could use some assembled units.

    I also did a test run of the SD, it works. I was able to open a file, fwrite() a txt line, and it showed up on the SD as expected. Now the bigger problem to deal with, since I plan to fwrite() global float values, anybody know how to do that. I tried:
    //global val1 = gbatt;
    int val1 = gbatt;
    fwrite(&gbatt, sizeof(gbatt),1,fp);
    

    and all I see in the file is strange chars. I did not see, in the Learn forum, anything about what can be done with fwrite(); Hopefully somebody has the answer.

    Ray
  • Due to ignorance and the fact that I have them lying around, I was considering simply plugging in a Micromite chip and using its internal flash storage. The 28pin device only needs an external cap and it's up and running. It can readily utilise an SD if more storage is required.
  • Not sure if you are suggesting that I switch to a Micromite chip, but I am committed to using the FLiP module, for this project anyway. If your next suggestion is to use the Micromite along side of the FLiP, I do not have the breadboard space to accommodate that. Besides that, I do not want to end up having too program two different chips, in two different languages. Thanks for the suggestion though.

    Ray
  • Below is a picture of my latest cmz configuration.

    The problem that I cannot solve is with the SD fwrite() function below. I started out with trying to write a float value to the SD, that did not work. Now, in the Learn forum, it shows an example of how to write a number value to the SD. Below I think I have basically replicated the code necessary, but I still get garbage chars, for the number, in the file, on the SD.

    So, is it equipment failure? The function below writes the text string without any problem. It is just having a problem writing a number to the SD card. When I get some today, I will have to do stand alone program for testing the SD functionality. I hope it is not a short coming with the SD function itself, although Parallax was very good at minimizing bugs like that.

    Yes, the snippet below runs as a COG, in the larger program.

    Ray
    /* COG2*/
    void unit_SD()
    {
        sd_mount(DO, CLK, DI, CS);
        pause(50);
        
        FILE* fp = fopen("test1.csv", "a");
        
        //float val1 = gbatt;
        //int level1 = readADC();
        //pause(1000);
        //int ubatt = ((((195*4010256)+5000)/1000000)*.01);
        int ubatt = 1049;
        
        fwrite("Testing 123...\n",1,15,fp);
        fwrite(&ubatt, sizeof(ubatt), 1,fp);
        fclose(fp);
        
    }
    
    1936 x 1296 - 736K
  • kwinnkwinn Posts: 8,697
    I suspect that the problem you are having writing out the floating point value is that you are writing it out in the format a float is stored in memory. Just as the byte 11111111 can be treated as the decimal value 255, it needs to be converted to a string of ascii digits to print it out. To write a floating point value to the SD you will need to convert it to a string of ascii digits. Those digits would then be written to the SD card. There should be a function in the floating point object to do the conversion.
  • Rsadeika wrote: »
    Not sure if you are suggesting that I switch to a Micromite chip.

    Ray

    Heck no but to save precious Prop cogs and code space, the MM is a useful peripheral device. The on-board BASIC interpreter is a breeze to use.
    Yeah I looked at your breadboard and wondered if a bit of re-shuffling would be possible.
  • Since I am still having problems with writing to the SD, I created a test program for the SD card.

    The below program basically follows the suggested guide lines for writing to the SD, which are presented on the Learn forum. The "int ubatt = 1049" shows up as garbage chars on the SD card, while the text portion shows up as expected. So, at this point I am not sure what is going on, and what the next step should be. Is it a PropGCC function problem, or is there some wiring connection that I am missing on the SD breakout board. Not even sure about what other test(s) I could try to narrow down the problem.

    Ray
    /*
      sd_test.c
      September 27, 2018 
    */
    #include "simpletools.h"
    #include "wifi.h"
    
    /* Init for SD */
    int DO = 15, CLK = 14, DI = 13, CS = 12;
    
    
    int main()
    {
      // Add startup code here.
      wifi_start(31, 30, 115200, WX_ALL_COM);  // Start WiFi
      pause(50);
      sd_mount(DO, CLK, DI, CS);
      pause(50);
      
      FILE* fp = fopen("test1.csv", "w");
    
      int ubatt = 1049;
    
      fwrite("Testing 123...\n",1,15,fp);
      fwrite(&ubatt, sizeof(ubatt), 1,fp);
      fwrite("\nWhere am I\n",1,20,fp);
      fclose(fp);
        
      while(1)
      {
        // Add main loop code here.
        
      }  
    }
    
    
  • MicksterMickster Posts: 2,588
    edited 2018-09-27 13:55
    Not that I've ever worked with SD cards but I seem to keep coming across reports of some cards work where others don't (?)

    Edit: Oh but a text string is no problem....only just picked up on that.
  • Dave HeinDave Hein Posts: 6,347
    edited 2018-09-27 14:29
    The value of 1049 is probably written to the file OK, but you are probably looking at the file wrong. If you are just viewing the file as a text file you aren't going to see the value of 1049 correctly. The values will be interpreted as ASCII characters, and 1049 does not produce any visible ASCII characters. You need to dump the file as a binary file to see binary values.
  • Dave HeinDave Hein Posts: 6,347
    edited 2018-09-27 14:39
    I ran your program on my PC, and then dumped the file in ASCII and HEX using od. The results are as follows:
    $ od -a test1.csv
    0000000   T   e   s   t   i   n   g  sp   1   2   3   .   .   .  nl  em
    0000020 eot nul nul  nl   W   h   e   r   e  sp   a   m  sp   I  nl nul
    0000040 nul nul nul nul nul nul nul
    0000047
    
    $ od -t x1 test1.csv
    0000000 54 65 73 74 69 6e 67 20 31 32 33 2e 2e 2e 0a 19
    0000020 04 00 00 0a 57 68 65 72 65 20 61 6d 20 49 0a 00
    0000040 00 00 00 00 00 00 00
    0000047
    
    The 1049 is interpreted as "em eot nul nul" in ASCII, and "19 04 00 00" in hex.

    Looks correct to me.
  • kwinnkwinn Posts: 8,697
    Dave Hein wrote: »
    I ran your program on my PC, and then dumped the file in ASCII and HEX using od. The results are as follows:
    $ od -a test1.csv
    0000000   T   e   s   t   i   n   g  sp   1   2   3   .   .   .  nl  em
    0000020 eot nul nul  nl   W   h   e   r   e  sp   a   m  sp   I  nl nul
    0000040 nul nul nul nul nul nul nul
    0000047
    
    $ od -t x1 test1.csv
    0000000 54 65 73 74 69 6e 67 20 31 32 33 2e 2e 2e 0a 19
    0000020 04 00 00 0a 57 68 65 72 65 20 61 6d 20 49 0a 00
    0000040 00 00 00 00 00 00 00
    0000047
    
    The 1049 is interpreted as "em eot nul nul" in ASCII, and "19 04 00 00" in hex.

    Looks correct to me.

    So saved as binary value rather than ascii digits.
  • If it is being saved to the SD card in a binary, how do I go about saving, in a form, that will be correctly visible on the SD card? Is the fwrite() command the correct or incorrect way to do this? I must also point out that in the Learn forum example, it does not state that the number would be correctly visible on the SD card file.

    So, I guess I need some guidance for the correct way to do what I am trying to accomplish. I wonder if other people have tried data logging in this method, and were getting a correct looking print out of the SD file.

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2018-09-27 15:32
    Use fprintf, or sprintf followed by fwrite. However, formatted prints pull in a lot of code from the libraries, so this could cause a problem with your executable binary size. In the past, I've written smaller versions of fprintf to reduce the code size. You could write a function that converts numbers to strings, and then write that out with fwrite if the code size is too big.
  • kwinnkwinn Posts: 8,697
    Rsadeika wrote: »
    If it is being saved to the SD card in a binary, how do I go about saving, in a form, that will be correctly visible on the SD card? Is the fwrite() command the correct or incorrect way to do this? I must also point out that in the Learn forum example, it does not state that the number would be correctly visible on the SD card file.

    So, I guess I need some guidance for the correct way to do what I am trying to accomplish. I wonder if other people have tried data logging in this method, and were getting a correct looking print out of the SD file.

    Ray

    Perhaps you could do the calculations using integers rather than floating point and then insert the decimal point after converting the result to ascii digits.
  • I checked the size of my big program, where the SD thing will be used, and the code size is 25,400. So, if I use fprintf or sprintf, that would add on another 5000, or so, to the 25,400. That does not allow for very much code expansion, since I am considering adding a couple of more sensors, and code to support it.

    The other thing that I have to consider is the html program that goes with this. At the moment I feed the html with float values and it is a breeze to deal with that in the html. Now if I switch to non float values then I am not sure what sort of complexity I will run into in the html code. Boy, this was going so easily, and I just about hit the brick wall, concerning memory availability. I guess I have to re-think what I am doing here.

    Ray
  • Here's the fprintf.c from p2gcc's library. I think I based it on Eric's simple printf code. Include this in your project and it will produce a smaller code size than if you use PropGCC's fprintf.
  • kwinnkwinn Posts: 8,697
    Rsadeika wrote: »
    I checked the size of my big program, where the SD thing will be used, and the code size is 25,400. So, if I use fprintf or sprintf, that would add on another 5000, or so, to the 25,400. That does not allow for very much code expansion, since I am considering adding a couple of more sensors, and code to support it.

    The other thing that I have to consider is the html program that goes with this. At the moment I feed the html with float values and it is a breeze to deal with that in the html. Now if I switch to non float values then I am not sure what sort of complexity I will run into in the html code. Boy, this was going so easily, and I just about hit the brick wall, concerning memory availability. I guess I have to re-think what I am doing here.

    Ray

    In your first post you mentioned that the log data would be stored as a .csv file. If the html program can handle floating point numbers from a .csv file then it does not matter if those numbers are produced by the floating point package and fprintf/sprintf or by integer math and insertion of the decimal point. In both cases they will appear as a string of ascii digits, possibly with an ascii decimal point. Both 123.45 and 678 would be valid floating point numbers to any software that deals with .csv files.

    If the floating point software fits in the available space then by all means use it. If not, then doing the calculations with integers and converting them to decimal digits is not that difficult, and results in smaller and faster code. I use integer math almost exclusively for converting sensor and adc readings to logged or displayed output readings.
  • I believe that I have come to the end of this project. I tried different things to get the data logging to work the way I want, to no avail.

    The project board is still useful, but it just does not have a working data logger component. Maybe in the near future, I will come across some idea as to how to make the data logging work, but not today. As for adding a couple of more sensors, and the corresponding support programs, not going to work, not enough memory available. Not sure what the next project will be, but I am more informed as to what the limitations of 32K memory are, with the Propeller chip and PropGCC.

    I suppose I could try to learn PASM, and recode everything in that, but I am not sure that that would even reduce the size of the program code.

    Ray
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-09-29 13:22
    Rsadeika wrote: »
    I believe that I have come to the end of this project. I tried different things to get the data logging to work the way I want, to no avail.

    The project board is still useful, but it just does not have a working data logger component. Maybe in the near future, I will come across some idea as to how to make the data logging work, but not today. As for adding a couple of more sensors, and the corresponding support programs, not going to work, not enough memory available. Not sure what the next project will be, but I am more informed as to what the limitations of 32K memory are, with the Propeller chip and PropGCC.

    I suppose I could try to learn PASM, and recode everything in that, but I am not sure that that would even reduce the size of the program code.

    Ray

    I have commercial Prop based dataloggers that do far more and include Ethernet servers and FAT32. I too encountered memory and speed limitations many years ago but I didn't accept that and stop there, which is why I developed the Tachyon "environment" for the Prop that runs on the Prop itself. You say you could learn PASM perhaps. Is PASM taught in colleges? No! Is it "popular" or "easy"? No, but it's not hard and neither is Tachyon. Now we even have it built into the ROM of the P2.

  • Thanks Peter.
    I do these things as a hobby, and this project was not intended to be for commercial value. I also do this to keep the mind active and agile, I am, after all 73 years of age, not an excuse, just a fact. So, as the popular saying goes, "I can see the light at the end of the tunnel".

    As for Forth, I have known about that language for, what, about thirty years now. If it was more of a scripting format, I would probably be more interested. I have really gotten used to the idea of the structured program style, it seems like I have more control over what the program is going to look like and do.

    Now as for the Tachyon "environment" , I am not so sure that you have all of the so called "functions" available to drive all the different components that I am using, and the primary one would be the WiFi. I also have the html component, which I use to get a quick glance as to what the components are reporting. True, that this would be a much better approach than using PASM, but …

    At this point I am open to a different approach to get the project to a complete working solution. Not sure as to how much energy I have to accomplish this, but it could be a really good reason to get up in the morning. Yeah, you young people will get old and will be experiencing the same things.

    Ray
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-09-29 14:29
    It's funny that you said that you like to have more control over what the program is going to look like and do since that is also a strong reason for me. I know if I write a function that it will work exactly like I told it to, just like PASM, there is no optimization magic going on to possibly disturb the other magic that I have going on.

    I thought the WiFi stuff was just plain serial which in Tachyon is as easy as saying "921,600 SERBAUD 5 SERIAL PRINT" HELLO WORLD" and it does just that. However my Ethernet servers are way more complicated than that of course since they handle the protocols. As for HTML isn't that a matter of serving up a web page from a file as I do now but using "Forth Script" instead of javascript? I'm not sure of your exact requirements as I haven't seen your code.

    As for knowing what you get, here I create a new demo function, test it, and then look at the code it produced. (bear in mind my simple HELP "decompiler")
    ...  : DEMO 10 FOR CR PRINT" HELLO WORLD"  NEXT ; 
    ...  DEMO 
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD
    HELLO WORLD ok
    ... HELP DEMO
    57CA 54C6 2 DEMO
    ADDR: DATA  NAME
    54C6: 800A  10
    54C8: 0128  FOR
    54CA: 044C  CR
    54CC: 04B6  (.")
    54CE: 4548  4548
    54D0: 4C4C  4C4C
    54D2: 204F  204F
    54D4: 4F57  4F57
    54D6: 4C52  4C52
    54D8: 0044  0044
    54DA: 0138  NEXT
    54DC: 0047  EXIT
    

    Opening and accessing a file is easy too: The ... are the prompts.
    ...  MOUNT 
    CARD: SU04G SD03.80 #C195.DBB1 2013/6 !C0FF.80B9 2,220us
    FAT: #E3FE.D79D mkfs.fat WIDGET      FAT32   3,965,190,144 bytes (4kB clusters)
     ok
    ...  DIR 
    WIDGET     
    DUMPV4  .FTH    .....a 0000.3B22 1390  m2016/12 /16   03:45   c2017/03 /23   04:26 480.  a2017/03 /23 
    EASYFILE.FTH    .....a 0000.3B2A  47k  m2016/12 /15   22:02   c2017/03 /23   04:26 480.  a2017/03 /23 
    EASYNET .FTH    .....a 0000.3B8A  42k  m2017/03 /21   14:02   c2017/03 /23   04:26 480.  a2017/03 /23 
    EXTEND  .FTH    .....a 0000.3BE2  41k  m2017/03 /22   23:04   c2017/03 /23   04:26 480.  a2017/03 /23 
    LIFE    .FTH    .....a 0000.3C3A 7046  m2017/03 /09   07:50   c2017/03 /23   04:26 480.  a2017/03 /23 
    LOVE    .WAV    .....a 0000.3C4A  14M  m2015/02 /16   08:06   c2017/03 /23   04:26 480.  a2017/03 /23 
    POPCORN .WAV    .....a 0000.ABEA 117k  m2014/06 /17   06:15   c2017/03 /23   04:26 480.  a2017/03 /23 
    SEEDAWN .FTH    .....a 0000.ACD2 1426  m2016/12 /15   14:24   c2017/03 /23   04:26 480.  a2017/03 /23 
    SPLAT-V4.FTH    .....a 0000.ACDA  18k  m2017/03 /09   12:30   c2017/03 /23   04:26 480.  a2017/03 /23 
    TACHYO~1.SPI    .....a 0000.AD02 200k  m2016/12 /16   07:32   c2017/03 /23   04:26 480.  a2017/03 /23 
    WARPEACE.TXT    .....a 0000.AE92   3M  m2015/08 /30   07:27   c2017/03 /23   04:26 480.  a2017/03 /23  ok
    ...   
    ...  FOPEN WARPEACE.TXT ...opened at 0000.AE92 for 3226652 
    ...  2 M 200 FS DUMP 
    001E.8480:   72 6F 62 61  62 6C 79 20  62 65 65 6E  20 77 6F 75    robably been wou
    001E.8490:   6E 64 65 64  20 69 6E 20  74 68 65 20  63 68 65 65    nded in the chee
    001E.84A0:   6B 2E 20 48  69 73 20 77  68 6F 6C 65  20 68 65 61    k. His whole hea
    001E.84B0:   64 20 77 61  73 20 77 72  61 70 70 65  64 20 69 6E    d was wrapped in
    001E.84C0:   20 72 61 67  73 0A 61 6E  64 20 6F 6E  65 20 63 68     rags.and one ch
    001E.84D0:   65 65 6B 20  77 61 73 20  73 77 6F 6C  6C 65 6E 20    eek was swollen 
    001E.84E0:   74 6F 20 74  68 65 20 73  69 7A 65 20  6F 66 20 61    to the size of a
    001E.84F0:   20 62 61 62  79 27 73 20  68 65 61 64  2E 20 48 69     baby's head. Hi
    001E.8500:   73 20 6E 6F  73 65 20 61  6E 64 0A 6D  6F 75 74 68    s nose and.mouth
    001E.8510:   20 77 65 72  65 20 74 77  69 73 74 65  64 20 74 6F     were twisted to
    001E.8520:   20 6F 6E 65  20 73 69 64  65 2E 20 54  68 69 73 20     one side. This 
    001E.8530:   73 6F 6C 64  69 65 72 20  77 61 73 20  6C 6F 6F 6B    soldier was look
    001E.8540:   69 6E 67 20  61 74 20 74  68 65 0A 63  61 74 68 65    ing at the.cathe ok
    
  • I have the C program and the html script attached, a couple of posts back.

    As for the WiFi part, I was also referring to the convenience of being able to program the FLiP module at a remote location.

    I was also considering PropBasic, but that language just simply does not have the language support that I would require. The requirements are just great, for me anyway, for it to be productive.

    So, what is left, Spin, that I believe would run out of memory in quick order also. Besides, I get really messed up with that indentation stuff. I do some programming in Python, and I also curse it, whenever I get caught up with the indentation quagmire.

    Back to Tachyon, does it have a scripting and then compile format? Or is it strictly an interactive format? I think I do not have to many more programing choices as to what can be done with the Propeller.

    Ray
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-09-29 14:52
    Terminology is useful and also a hindrance. You say "scripting" and then "compile format". It makes no real difference in Tachyon as you can send it a line of text that it will compile temporarily and then run at compile speeds, so you can include loops etc. But you can also tell it to save that code as a named function which is very fast and compact Tachyon code that becomes part of the language, you can even enhance the compiler itself like this.

    For instance, this "script" can be sent over serial and executed like this
    10 FOR CR PRINT" HELLO WORLD" NEXT
    
    or you can save it with a name
    : DEMO 10 FOR CR PRINT" HELLO WORLD" NEXT ;
    
    and then run it at any time with
    DEMO
    

    Is this what you are getting at?

    But it is very easy to try it, just download it and connect a terminal at 115200 baud etc.
  • Lets see if can get my idea of scripting described. I use Python, in the scripting manner. What I do is open a Geany IDE, type in the lines of code, hit the run button, and it does its thing. Or I think it can also be compiled and run that way. Yes, I know that Python can also be done in an interactive format, I guess, just like what you have with Tachyon.

    I am not sure if I remember correctly, but I think the original forth was a compiled format, meaning you would write the code, in a file format, than you would compile it, and run it? Anyway, I am not a big fan of the interactive programming style.

    Ray
  • Ray,

    Can your post a zipfile of your project? I suspect there are a few things that could be done to reduce the binary size. Did you try the fprintf that I posted? That should help.

    Programming in C on the P1 is a challenge because of the 32K of RAM. The P2 will be a great chip for running C code because it doesn't have the same memory limitation. You could try using CSPIN to convert your C code to Spin. This should produce a smaller binary size. Or you could write it in Spin and used FSRW for the SD file driver.

    Anyhow, if you could post a zipfile of your project I might be able to give you some tips on how to make it fit within 32K.
  • Thanks Dave.
    At the moment I am testing your fprintf() command, yes it is using a lot less code. I am testing the RTC data output, luckily it provides the output in a hex format, so fprintf() can deal with that using "%x".

    It would be nice if your fprintf() had a "%f", to deal with the float numbers, then I would be all set, I think.

    The other problem that I am seeing is how fprintf() is placing the data in the file. For instance, if I have this:
    fprintf(fp,"%x/%x/%x",month,day,year);
    fprintf(fp,",%x:%x:%x",hours,minutes,seconds);
    
    fprintf(fp,",%d",gtemp);
    fprintf(fp,",%d",ghumid);
    
    it seems that in the file it shows up as, 60,70,14:14:14,09/29/18. What I really want is, 09/29/18,14:14:14,70,60. Something I am not catching on to with the way the data stream is working.

    Since the gtemp and ghumid are float, when I use fprintf(), the values are showing up as a eight digit number that does not look like the float number at all.

    Ray
Sign In or Register to comment.