Any Raspberry Pi webserver folks out there?

jsmanson

Member
I know, this is a picaxe forum, not a Pi forum. However, I'm trying to set a a communication setup between a raspberry Pi running a webserver, through a wiznet 110Sr ethernet to serial converter board to my 40x2 running a water monitoring program. So there is a picaxe in the mix there somewhere!!

I want to be able to call up the Pi server in a remote browser, monitor things, and send commands to the picaxe through the wiznet. At present, I can chat with the picaxe using a telnet session on my windows PC, or on the Pi, without any problem. I send it little action codes, and the picaxe responds back through the wiznet as programmed.

The hard part comes next. I am a complete noob at webservers, I have dabbled a bit with php, and I could probably learn python as that seems to be the programming language of choice on the pi. I'd appreciate any comments from you on what would be the easiest way to host a website which can do this communication. To date, playing around with php and sockets on the pi, I haven't had any success at getting an answer back from the wiznet/picaxe when I just program it (the picaxe) to echo back what it hears. I know that when doing communication using htmp, rather than telnet, the wiznet isn't getting any data through as I can monitor the serial side of the wiznet using a terminal attached to the serial. So I am struggling to figure out how I can get a web server to send out data just like a simple telnet session does.....

Thanks in advance!

John
 

MPep

Senior Member
Hi John,

I see you've had 24 posts already, so surely you must have realised that this part of the forum is for Finished Projects.
Please re-post in the general forum, where you'll get more responses.

MPep
 

lbenson

Senior Member
If the R-Pi is running the webserver, what is the wiznet needed for? You can communicate between the R-Pi and the picaxe either via serial or I2C, with the picaxe 40X2 being an I2C slave.

By the way, the html "template" that I used in the PICAXE Web Server for water system control could also be used on the R-Pi (that's the beauty of the template--I've used it on a PC, on the older (and discontinued) wired SimpleLan with a picaxe, on openWrt Linux routers, and on small debian devices like the R-Pi). I have a lua program (which could run on the R-Pi), which could plug information into the html template. (Any other language would work as well, but I like Lua--it's lightweight and runs almost everywhere (not on a picaxe).)

The 40X2 could place the sensor readings in its scratchpad memory (bytes 0-255), and the R-Pi could pick them up using I2C and plug them into the html template. There was a posting on the picaxe forum on the use of I2c for interaction between the R-Pi and a picaxe--try a search.

Here's the site: http://www.picaxeforum.co.uk/showthread.php?25113-Picaxe-as-an-efficient-I2C-slave-to-RasPi-one-caveat

Run the picaxe at 3.3V or use a level shifter to communicate with the 3.3V R-Pi.
 
Last edited:

jsmanson

Member
I like LBenson's idea about using the raspberry to directly read the 40x2's scratchpad as an i2c master, but does that mean that I can't use the 40x2 to be an i2c master for reading other parts connected to the 40x2? I am a bit confused about if its possible to have 40x2 run two separate i2c buses at the same time or if not, can the pic can switch between master and slave mode, if if it can, I'll need to think about how the raspberry can wait until it can be the master again. I have got the rasp and pi talking via serial just fine, so I could go that route, but I like the direct read of scratchpad via i2c better!
 

lbenson

Senior Member
The 40X2 can't be both master and slave simultaneously, but it could switch between the two and use a R-Pi gpio pin to signal that it's in slave mode.

What I2C functions are you looking at? If only date and time, then the R-Pi could take that over, reading the time from DS1307 or equivalent, and putting it into the 40X2's scratchpad, for instance, minute by minute. I don't think the R-Pi has built-in hardware clock, but Linux has built-in time-keeping, and could be kept on time with occasional uses of "rdate" or "ntpd". This time could also be placed in the 40X2's scratchpad minute by minute.
 

jsmanson

Member
Hi Lance, I was going to use i2c for a clock, temp probe, eeprom (not sure I need this, I can use the pi for data storage through the interface), so yes I could move these bits over to the pi, and use python to manage them. At the moment, I'm stuggling to get the pi to write and read from the pic's scratchpad. I don't have a level shifter here at the moment, so that may be the problem, I'm mixing the 5 and 3.3 volts parts together as I've got an old 40x2, 5v only. Interestingly, I can 'see' the pic from the raspberry by using the "i2c detect -y 1" command, it comes back with the address (set it to 0x5a), but the pic doesn't detect a write to the scratchpad through the flag, and if I read the address from the pi, it's zero, and the pic displays 0 as well. The pi isn't reading the scratch when I have stuck numbers in there as well. So it's probably the level shifting, time to order a part and take a rest from the project.
 

jsmanson

Member
One i2c Device that I need on the picaxe is a digital pot. It will be used to set the voltage on the variable DC pump(s), it's running off a variable output power supply. Direct addressing through i2c would really nice to have, but I guess i could do a serial version..
 

lbenson

Senior Member
You could certainly damage the Raspberry Pi with 5 volt inputs, and may already have.

Someone please correct me if I'm wrong, but I think all you need is to have the I2C pullups go to the R-Pi 3V3 instead of to 5V. I don't think it matters then if the picaxe is running at 5V. If you're using one of the I2C clock modules with pullups to 5V built in, you would have to remove those pullups.

Some of those DS1307 clock modules appear to run only at 5V, but the newer and more accurate DS3231 works at 3V3.
 

hippy

Ex-Staff (retired)
Someone please correct me if I'm wrong, but I think all you need is to have the I2C pullups go to the R-Pi 3V3 instead of to 5V. I don't think it matters then if the picaxe is running at 5V.
That would be my expectation as I2C interfaces are notionally open-collector drives.

However, for PICAXE and other 5V devices, their I2c bus pins may not solely or purely be open-collector so there can be some leakage which has 5V appearing on those pins which could be applied to a Pi pin, even if at very low current. The hardware designers of the Pi say their device is at risk of damage with any over-voltage, has a far lower tolerance to injection currents than PICAXE and other devices do. Only the Pi designers can provide a definitive answer on this.
 

lbenson

Senior Member
Nice level-shifting document for I2C 3V3-5V.

The significant diagram shows two signal mosfets, one on SDA and one on SCL, with gates tied to 3V3, source on the 3V3 side, drain on the 5V side, and pullups on both sides.
 
Top