PICAXE and OLED screen communication

Andie

Member
Hi all,

I am currently using an 18M2 chip to control the lighting of three different LEDS based on three different inputs and the chip sends out text to an OLED screen,
I am also using an 08M2 chip as a timer. I am trying to connect the two PICAXEs using serin/out commands so that the OLED screen will display the previous running time before the power was turned off. Is this possible?

18M2:
Code:
init: pause 1500	;wait for disply to initialise
	serout b.4,N2400, (254,1)	;clear screen
	input b.5
	serin b.5,N2400, (b0,b1,b2,b3,b4)
	pause 30
	serout b.4,N2400, (254,128,"Previous running")
	serout b.4,N2400, (254,192,"time: ",b0,b1,b2,b3,b4,"s")
	wait 5
	serout b.4,N2400, (254,1)
	
main: if pinc.0 = 0 then goto reda ; move to reda to turn red light on when the current stops
	if pinc.1 = 0 then goto redb ; move to redb to turn red light on when the extraction tube stops
	if pinc.2 = 0 then goto redc ; move to redc to turn red light on when the magnetic stirrer stops
	low b.3 ; blue light off
	low b.2 ; red light off
	high b.1 ; green light on
	serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,129,"All systems OK") ; display "all systems OK" on OLED screen
	pause 500 ; pause for 1 second
	goto main ; start again
	
reda: low b.1 ; green light off
	high b.2 ; red light on
	serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,133,"Current") ; display "current off" on OLED screen
	pause 500; pause for 1 second
	if pinc.1 = 0 then goto reda1 ; move to reda1 to keep red light on if extraction tube also stops
	if pinc.2 = 0 then goto reda2 ; move to reda2 to keep red light on if magnetic stirrer also stops
	if pinc.0 = 1 then goto main ; start program again if the current returns
	goto reda ; start again
	
reda1:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,129,"Current and fan") ; display "current off and extraction fan not working" on OLED screen
      pause 500 ; pause for 1 second
      if pinc.2 = 0 then goto blue ; move to blue to turn blue light on if the magnetic stirrer also stops
	if pinc.0 = 1 then goto main ; start program again if the current returns
	if pinc.1 = 1 then goto main ; start program again if the extraction fan starts working again
	goto reda1 ; start again
	
reda2:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,130,"Current and") ; display "current off and magnetic stirrer not working" on OLED screen
	serout b.4,N2400, (254,196,"stirrer")
      pause 500 ; pause for 1 second
      if pinc.1 = 0 then goto blue ; move to blue to turn blue light on if the extraction fan also stops
	if pinc.0 = 1 then goto main ; start program again if the current returns
	if pinc.2 = 1 then goto main ; start program again if the magnetic stirrer starts working again
	goto reda2 ; start again
	
redb: low b.1 ; green light off
	high b.2 ; red light on
	serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,134,"Fan") ; display "extraction fan not working" on OLED screen
	pause 500 ; pause for 1 second
	if pinc.0 = 0 then goto redb1 ; move to redb1 to keep red light on if current also stops
	if pinc.2 = 0 then goto redb2 ; move to redb2 to keep red light on if magnetic stirrer also stops
	if pinc.1 = 1 then goto main ; start program again if the extraction fan starts working again
	goto redb ; start again
	
redb1:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,129,"Current and fan") ; display "current off and extraction fan not working" on OLED screen
      pause 500 ; pause for 1 second
      if pinc.2 = 0 then goto blue ; move to blue to turn blue light on if the magnetic stirrer also stops
	if pinc.0 = 1 then goto main ; start program again if the current returns
	if pinc.1 = 1 then goto main ; start program again if the extraction fan starts working again
	goto redb1 ; start again
	
redb2:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,129,"Fan and stirrer") ; display "extraction fan and magnetic stirrer not working" on OLED screen
      pause 500 ; pause for 1 second
      if pinc.0 = 0 then goto blue ; move to blue to turn blue light on if the current also stops
	if pinc.1 = 1 then goto main ; start program again if the extraction fan starts working again
	if pinc.2 = 1 then goto main ; start program again if the magnetic stirrer starts working again
	goto redb2 ; start again
	
redc:	low b.1 ; green light off
	high b.2 ; red light on
	serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,132,"Stirrer") ; display "magnetic stirrer not working" on OLED screen
	pause 500 ; pause for 1 second
	if pinc.0 = 0 then goto redc1 ; move to redc1 to keep red light on if current also stops
	if pinc.1 = 0 then goto redc2 ; move to redc2 to keep red light on if extraction fan also stops
	if pinc.2 = 1 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc ; start again
	
redc1:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,130,"Current and") ; display "current off and magnetic stirrer not working" on OLED screen
	serout b.4,N2400, (254,196,"stirrer")
	pause 500 ; pause for 1 second
      if pinc.1 = 0 then goto blue ; move to blue to turn blue light on if the extraction fan also stops
	if pinc.0 = 1 then goto main ; start program again if the current returns
	if pinc.2 = 1 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc1 ; start again
	
redc2:serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,129,"Fan and stirrer") ; display "extraction fan and magnetic stirrer not working" on OLED screen
      pause 500 ; pause for 1 second
      if pinc.0 = 0 then goto blue ; move to blue to turn blue light on if the current also stops
	if pinc.1 = 1 then goto main ; start program again if the extraction fan starts working again
	if pinc.2 = 1 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc2 ; start again
	
blue: low b.2 ; red light off
	high b.3 ; blue light on
	serout b.4,N2400, (254,1)
	pause 30
	serout b.4,N2400, (254,132,"Finished") ; display "finished" on OLED screen
	pause 800 ; pause for 3ms
	if pinc.0 = 1 and pinc.1 = 1 and pinc.2 = 1 then goto main ; if all three components start working again start program from beginning
	goto blue ; start again
08M2:
Code:
init:	enabletime
	read b0,w8
	serout c.4,N2400, (#w8)
	wait 5
	
main:	let w7 = time
	write b0,w7
	goto main
Thanks in advance!
A
 

hippy

Ex-Staff (retired)
serout c.4,N2400, (#w8)

serin b.5,N2400, (b0,b1,b2,b3,b4)

If those two are communicating the problem likely is that #w8 won't always send five bytes. The most appropriate remedy is probably to use BINTOASCII to convert w8 to five bytes and send those.
 

Andie

Member
Thanks hippy

I now have
Code:
init: pause 1500	;wait for disply to initialise
	serout b.4,N2400, (254,1)	;clear screen
	input b.5
	serin b.5,N2400, (b1,b2,b3,b4,b5)
	pause 30
	serout b.4,N2400, (254,128,"Previous running")
	serout b.4,N2400, (254,192,"time: ",b1,b2,b3,b4,b5,"s")
	wait 5
	serout b.4,N2400, (254,1)
and
Code:
init:	enabletime
	read b0,w8
	bintoascii w8,b1,b2,b3,b4,b5
	serout c.4,N2400, (b1,b2,b3,b4,b5)
	wait 5
The OLED screen clears and nothing else, and none of the LEDs come on...
 

BeanieBots

Moderator
Try setting w0 to a known value such as 12345 whilst testing so that you can at least eliminate any other issues first.
In your first code you have a loop which writes rapidly to EEPROM.

Please be aware that EEPROM has limited write capability and will quickly be damaged by such rapid writes.
 

hippy

Ex-Staff (retired)
Also try a much simpler receiver program that can check / show what you are receiving.
 

Andie

Member
When I simulate it on programming editor the serin keeps asking for an input no matter how many times type in some values.
However, if I simulate a timeout the code works fine. Is there a way to incorporate a timeout in the code?
A
 

hippy

Ex-Staff (retired)
Is there a way to incorporate a timeout in the code?
Yes, but whether you want one or not depends on what the problem is you are trying to solve.

A SERIN without a timeout will wait for the data to be received, won't do anything until it is. But if you have a timeout and data is sent while the receiver isn't looking for that data then it could be missed, data may never be seen.
 

Andie

Member
It's is all working fine on the simulation so I am assuming it is something to do with the circuit itself.
I have connected the two pins directly to each other with a wire on the AXE091U experimenter board. Do you think this could be the problem?

A
 
Top