using a 40x1 instead of a PCF8570P

JonathanA

New Member
Hi everyone thanks for a great forum
This is the first time I have requested any help in the 4 years I have been using Picaxe chips so I hope I have included enough info for you. I have been using a PNS to display information from my home automation projects, after running out of RTC ram on my PNS I removed the Picaxe 28x and used a 40x1 as a i2c slave so I can increase the ram from 56 to 128 bytes with no need to access the i2c bus while updating the scratchpad memories. The hardware is working but I am having problems writing the HTML code. I would like to display the first 7 scratchpad memories 000 to 006 on one page and update them every 10 seconds. Every attempt I make only the last checked value is displayed and I have to use a submit button to start it off. I have cut down my BattVolt.cgi page to 2 memories while testing 000 & 001.
Code:
<html>
<meta http-equiv="refresh" content="10">
<head><title>Battery Voltage</title></head>
<body><center>

<table border=1 width=95%>
<tr>	
<form method=get>
	<td>
	<input type=hidden name=32 value=000>
	<input type=submit value="Batt 1">
	</td>

	<td>
	Battery 01 = ?AD189 ?AD289 . ?AD389 v
	</td>
</form>
</tr>

<tr>	
<form method=get>
	<td>
	<input type=hidden name=32 value=001>
	<input type=submit value="Batt 2">
	</td>

	<td>
	Battery 02 = ?AD189 ?AD289 . ?AD389 v
	</td>
</form>
</tr>
</table>
</body>
</html>
It's the first time I have had to use commands 32, 33, 34 and command 33 set address and read gives unexpected results but command 32 without any data gets the correct values from the 40x1 scratchpad memories. Could someone please tell me where I am going wrong with this as the manual is very light on information on how to use the PCF commands. My HTML skills are not very good but I have managed to get most things working when using the RTC memories so please excuse any basic mistakes as its mainly trial and error for me at the moment with HTML. Thanks in advance for any help Jonathan
 

JonathanA

New Member
Thank you for your reply Technical.
I find when I have a problem I cut all my code down to the problem area only, so this is the 40x1 program I have been testing with. It's only job is to increase the scratchpad memory by 1 each 15 seconds so I have fresh data all the time and memory 000 and 001 are not the same. The chip is an A.0 firmware
Picaxe 40x1 code
Code:
'Directives
#Picaxe40x1
#Com Com13

Init:
	hi2csetup i2cslave, %10100010	'Set chip up as EEProm address 001
	'Init each scratchpad slot with a different number
	For B1 = 0 to 127
	Put B1,B1
	Next B1
	
Main:
	Pause 15000	'Pause 15 seconds
	For B1 = 0 to 127
	Get B1,B0
	Inc B0
	Put B1,B0
	Next B1
	Get 0,B0,B1	'get scratch pad memory zero & one
	Sertxd (#B0," - ",#B1,Cr,Lf)
	Goto Main
 

Technical

Technical Support
Staff member
There are two ways to write the data.

In this first example data value 88 is written to address 001

<input type=hidden name=32 value=001088>

In this second example whatever someone types in the text box is saved at 001

<input type=hidden name=33 value=1>
<input type=text name=34 value=88>

After these commands are processed the actual value can be dispalyed via variable ?89
To read two addresses you need to submit a command in between each use of ?89!

<input type=hidden name=33 value=001>
Current Address ?88 = value ?89

...

<input type=hidden name=33 value=002>
Current address ?88 = value ?89
 

JonathanA

New Member
Thank you for your reply Technical
I agree with all your statements in post 4 and that is where I got stuck 3 weeks ago but I think I am starting to understand why when I use a single commands 33 and 34 together all works as expected but when I use two commands on the same page my problems start.

<input type=hidden name=33 value=0>
<input type=hidden name=34 value=0>
Current0 address ?88 = value ?89
<br>
<input type=hidden name=33 value=1>
<input type=hidden name=34 value=1>
Current1 address ?88 = value ?89

I think both requests are processed at the same time in the PNS so it sets the address as 0 then reads but does not return ?88 or ?89 to the browser but still continues to process the second request sets the address to 1 then reads so what is returned to the browser is just the last request ?88 and ?89. So in my example ?88 displayed @ current0 and Current1 are both 1 as that was the last address processed. I have found by using frames and two seperate cgi pages as the src it will work not very well but it does work. Unless someone can suggest another way that I have missed I will return to having the Picaxe writing to the RTC and try changing the data held in the RTC depending on the page to be displayed. It just seemed such a good idea at the time. Thank you for your help though, I think there is a clue to another answer on page 41 of the manual it says that "use javascript to process 2 or more consecutive GET commands" but unfortunately having looked at Java script on the internet I could not work out how, but it is on my list of things to learn when I have time.
 

Technical

Technical Support
Staff member
I think both requests are processed at the same time in the PNS so it sets the address as 0 then reads
If you don't 'submit' between the two lines then yes, they are sent at the same time in one GET and hence the ? data read back does not read as you expect.

You basically need to summit a GET, then read the data, then submit the second GET
 

JonathanA

New Member
Hi Simon thank you for your reply and apologies for late response unfortunately lost my
job of 29 years on Wednesday so PNS has moved down my to do list, find new job now being top. I have looked at your site and it does seem very advanced at the moment but I have started to look at Java. My first Java program to add a + or - to my temperature display has come together much easier than I thought, although I have not got it to work with real PNS variables yet. I will continue along this line though but will have put it on hold at the moment.
Thanks
Jonathan
 
Top