Some of the pins from the tutorial may need to be changed, as most of those mentioned are in use by the Bela cape ( http://bela.io/archive/faq.html#19 ). If you choose to use pins addressed by the Bela Digital I/O, then I think you could write from it straight from the Bela audio thread!
!!!!
Not tested/never used it before!
Hooking up an LCD
Actually it looks like it requires more than the 3.3V the digital pins can provide, so you may have to use the analog outs (which can get up to 5V).
Should've added I have developed my instrument in Pure Data.
Apart from PD, anything else I need to learn will be completely new to me.
So I will need to learn C++ or Python in order to make my instrument display something on a screen?
And then how will I make the PD patch communicate with the C++ or Python code?
perhaps i am going to be way out of my depth……...
- Edited
If you are using the analog outs, then you can use Pd, but you will need to come up with the appropriate way of writing the correct "bits" to the outputs. You will have to familiarise yourself with the underlying binary communication described here http://www.protostack.com/blog/2010/03/character-lcd-displays-part-1/ and obtain that in Pd. Challenging, but it should be doable (probably using the 4-bit mode, as you will need 6 outputs in total to also write the enable and RS channels )
It may sound intimidating to begin with, but the process can be broken down into three more straightforward steps:
Get your LCD screen working with one of libraries referenced above. I would recommend the nodejs option, as that uses javascript which is a relatively nice language for inexperienced developers, and has an API based on Liquid Crystal for Arduino. Note, you will need to swap some of the pins on the P8 header which are used in the example, as they are used by Bela (to see which pins Bela uses, take a look at our handy interactive pin diagram).
Send the text you want to display from PureData over OSC. OSC stands for open sound control, it's a way of communicating between different programs, particularly when building musical systems. It's very common to send OSC messages from PD, see here for an example (note you will need to use IP address 127.0.0.1).
Receive the OSC messages in nodejs, and pass them to the LCD screen. I would recommend using osc-min for this.
It sounds complicated I know, but being able to send osc messages around is a powerful and useful skill! Feel free to ask any questions here if you get stuck.
Thanks! I am sure I'll be back for help but that breaks it down into 3 steps that sound possible.
- Edited
Well I WAS way out of my depth and I chose the bloody-minded route to do it in PD regardless of it being a bit crazy..... still a smaller time investment than learning new programming languages at this stage.
For anyone else who needs it, here is a PD patch that will initialise an HD44780 compatible LCD and display messages on there.
You have to make sure you LOADBANG the INITIALISE subpatch.
Then simply send a message to "string" and it will be output from the analogue outs on Bela to your LCD.
The patch supports capital letters, numbers, and the following other characters: . : - ! ?
It outputs a solid square if it receives a #. It outputs an outline square if it receives a |.
You must use _ instead of "space" in your messages and you can use @ to clear the display and * to display on line 2 of the display.
You could easily expand it to display lowercase and more punctuation if you need it.
It uses the 4 bit interface mode of the display so you only need 6 analogue outs on the Bela, as follows:
Bela out 7 to LCD D7
Bela 6 to D6
Bela 5 to D5
Bela 4 to D4
(D3 to D0 tied to ground)
Bela 3 to RS
Bela 2 to Enable
https://github.com/nuromantix/PD-bela-stuff/blob/master/LCD_Driver.pd
https://github.com/nuromantix/PD-bela-stuff/blob/master/bela_44780_lcd_driver.pd
Thanks that looks great. Surely github needs a plugin to display pure data patches in the browser
By any chance, did you test this with the digital outs as well? Or were the voltage levels not compatible?
I couldn't get the display to power up from 3.3 volts but it is probably enough for the logic.
So you could power from the 5V rail but use digi outs for the logic.
I wasn't brave enough to risk mixing up the wires in case I fried the Bela!
Awesome, this is really great!
We should probably think about ways of sharing/distributing community-contributed code and pd objects etc like this.
Thought I ought to give something back after all my beginner questions......
- Edited
Hi nuromantix , I'm trying to use your LCD driver but am a bit lost with the messages. What, in the patch, is prompting something to be sent to the LCD? It seems like the is but I'm not sure how to bang the message once it's in the BELA. Forgive me if this is simple, I'm fairly new and a bit over my head but very excited about the driver you made!
SOS'ed. Not sure what happened there
I'll add to the mix of suggestions something that simplifies this for me.
Adafruit LCD USB backpack:
https://www.adafruit.com/product/782
Then power comes from your BBB USB port and it shows up as a USB TTY device, which should be really easy to use from Pd (I'm talking to it using C++ directly).
Some extra advice on this USB backpack is the code shipped from Adafruit is a little bit buggy (weird stuff happening with read/write EEPROM), so custom characters and saved stuff get garbled and mixed up sometimes.
The github user CanyonCasa fixed the bugs and added some nice features (GPIO):
https://github.com/CanyonCasa/BackpackPlus
I forked this and added an audio level meter and some other small things that strike my fancy:
https://github.com/transmogrifox/Adafruit_USB_Backpack_Plus
Also I added the .hex file for the EEPROM clearing utility, so hypothetically all you need is AVRdude and the instructions on my github to flash this image if you want to.
The image from Adafruit works mostly ok, so there are only some odd behaviors you will notice when you try to do stuff with custom characters or RGB backlighting saved settings.
- Edited
Sending messages to @string do work. But you have to add @ at the start of a new line. There are examples at the LCD driver patch. You should also check the connections from analog out. It all works for me. But some isolation circuit might be needed because LCD consumes lots of energy and makes voltage lower than usual. Try this scheme:
http://howtomechatronics.com/wp-content/uploads/2015/07/LCD-Display-Tutorial.png?x57244
Some of the nodes need to be shorted together. So order of the upper nodes are like this
[GND, 5V, GND, BELA, GND, BELA, GND, GND, GND, GND, BELA, BELA, BELA, BELA, 5V, GND]
hope this is not too off topic, but if one wanted to hookup a rectangular display (without touch) of some sort: what would be the easiest solution on the bela? a tft? lcd? oled?
not sure. Some details on using an OLED display here https://forum.bela.io/d/314-does-anyone-successfully-using-i2c-oled-lcd/3
Thanks for the pd patch @nuromantix
I've tried breadboarding this with a HD44780 but couldn't get it working yet
First attempt was using the routing mentioned:
Bela out 7 to LCD D7
Bela 6 to D6
Bela 5 to D5
Bela 4 to D4
(D3 to D0 tied to ground)
Bela 3 to RS
Bela 2 to Enable
Then I noticed in the 'send_to_output' sub patch that it shows digi pin inputs on the LCD routed slightly differently:
Bela out 7 to LCD D0
Bela 6 to D1
Bela 5 to D2
Bela 4 to D3
(D4-D7 to GND)
This didn't work either.. The LCD backlight does come on. I've got an alternating message box being sent to string (printed to console to verify it's working)
Has anybody got any idea where it's going wrong? Or any recommendations for using other LCD/OLED with Pd... i'm open to changing the screen if necessary.
Thank you