1. euphoria to arduino
- Posted by johnrpm Jan 09, 2012
- 2415 views
I wonder if anyone can help, I am trying to get euphoria to turn pins on and off on an arduino using serial, I am using an include file from " serial communications" in the archive posted by Kondor Attila in 2005, I can send a individual char using the function (sio_putch), but can not send a string using (sio_write), I need this to turn on multiple pins, here is the function.
----------------------- sio_write ----------------------- global function sio_write(integer port, integer lpWBuf, integer len) return c_func(sio_write_,{port, lpWBuf, len}) end function
the help file indicates this..... sio_write (port, "ABCDE", 5)
lpWBuf is an integer, so how do I send a sequence, this may be a stupid question, but I am probably the worlds worst programmer.
2. Re: euphoria to arduino
- Posted by ArthurCrump Jan 09, 2012
- 2370 views
The parameter lpWBuf is probably a pointer to the string, as in the raw C function.
Try
return c_func(sio_write_,{port,allocate_string(your_string,1),5})
Arthur
3. Re: euphoria to arduino
- Posted by johnrpm Jan 09, 2012
- 2365 views
Thanks Arthur, I will give it a go tonight, I was not kidding about being the worlds worst, so will probably need to come back for help.
John
4. Re: euphoria to arduino
- Posted by johnrpm Jan 09, 2012
- 2308 views
Thanks again Arthur, it worked, also changed lpWBbuf to object
----------------------- sio_write ----------------------- global function sio_write(integer port, object lpWBuf, integer len) --return c_func(sio_write_,{port, lpWBuf, len}) return c_func(sio_write_,{port,allocate_string(lpWBuf),8}) end function
I can now send a string of 8 bits to turn on or off 8 LED's, which will be transistors eventually.
5. Re: euphoria to arduino
- Posted by mattlewis (admin) Jan 09, 2012
- 2308 views
Thanks again Arthur, it worked, also changed lpWBbuf to object
----------------------- sio_write ----------------------- global function sio_write(integer port, object lpWBuf, integer len) --return c_func(sio_write_,{port, lpWBuf, len}) return c_func(sio_write_,{port,allocate_string(lpWBuf),8}) end function
I can now send a string of 8 bits to turn on or off 8 LED's, which will be transistors eventually.
Note that the way you have written this, you will end up leaking memory. I don't know how long your program runs, or how often this function is called, but eventually, it will eat up all of the memory on your system.
The function, allocate_string() allocates memory from the operating system. If you are using Euphoria 4.0, you can add an extra parameter (which Arthur did) to specify if it should be freed when all of your references go away. This uses a new feature for 4.0. However, if you're using 3.1, then you'll need to do something like this:
global function sio_write(integer port, object lpWBuf, integer len) atom ptr, ret ptr = allocate_string( lpWBuff ) ret = c_func(sio_write_,{port,allocate_string(lpWBuf),8}) free( ptr ) return ret end function
If you know that you'll be using a particular size string (say, 8 bytes), then you could do something like this:
constant ptr = allocate( 8 ) global function sio_write(integer port, object lpWBuf, integer len) poke( ptr, lpWBuff ) return c_func(sio_write_,{port,ptr,8}) end function
That way, you save yourself the time of allocating and freeing the memory constantly.
Matt
6. Re: euphoria to arduino
- Posted by johnrpm Jan 09, 2012
- 2295 views
I have both 3.1 and 4 installed, but do not yet feel confident with 4, so the plan is to get things working, then port it over to 4, Thank you both for the excellent help, I am trying to build a large format printer, the image is processed with tommys win32dib, which writes a file of the pixel colours and this file is read which moves the motors and fires the printhead through the arduino and an interface board.
Thanks again John
7. Re: euphoria to arduino
- Posted by lpuster Jan 26, 2012
- 2202 views
I wonder if anyone can help, I am trying to get euphoria to turn pins on and off on an arduino using serial, I am using an include file from " serial communications" in the archive posted by Kondor Attila in 2005, I can send a individual char using the function (sio_putch), but can not send a string using (sio_write), I need this to turn on multiple pins, here is the function.
----------------------- sio_write ----------------------- global function sio_write(integer port, integer lpWBuf, integer len) return c_func(sio_write_,{port, lpWBuf, len}) end function
the help file indicates this..... sio_write (port, "ABCDE", 5)
lpWBuf is an integer, so how do I send a sequence, this may be a stupid question, but I am probably the worlds worst programmer.
This is just an educated guess: Try using allocate to reserve some space for your buffer. Allocate returns the address of the buffer. Then poke the string into the buffer. Finally, call sio_write with your port, the address of the buffer, and the length of the sequence. Then release your buffer. Or, if you don't care about reading a reply, you can simply open a serial port like this: comm = open("COM1", "wb") then write to it with puts(comm, "The Data"). (This all assumes you have set the com port parameters beforehand.)
8. Re: euphoria to arduino
- Posted by alanjohnoxley Jan 27, 2012
- 2138 views
Hi,
I have nothing against the Arduino, but there are other ways to do interfacing once you are happy with your prototype.
For example, check out the range of "PIC" programmable chips from Microchip, these cost a few dollars and have many ports.
You would need to get some interfacing electronics to program it of course, but thats less than an Arduino and the PIC chip, and you keep the programmer forever.
HTH! No, am not a Microchip employee :)
9. Re: euphoria to arduino
- Posted by alanjohnoxley Jan 27, 2012
- 2146 views
There is another bit of kit similar to the Arduino, search this forum for "Vellerman K8055 interface" for an example that was very easy.
10. Re: euphoria to arduino
- Posted by johnrpm Jan 29, 2012
- 1937 views
Thanks for the good advise, I did use pic chips at one time, still have loads of c16f84, I could not get my head around assembler so used JAL, still have it somewhere, but when the Arduino came out it made things simpler, I also have some of the velleman boards, I even managed to write a wrapper in euphoria, which shows how good Euphoria is if I can do it, the velleman boards are an option if all else fails, but they are a bit short on input output.
Thanks again for the help, its only a matter of time befor I am back again asking for help