Author Topic: mcModules goes touch  (Read 989 times)

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
mcModules goes touch
« on: June 15, 2016, 03:04:40 am »
Hello.
Here is my first project contribution to this forum.

I use several Android tablets mounted on walls in my house to control and verify things and the communication i use there is MQTT so mcModules MQTT support feels very natural for me. Something that i need is very small touch screen and the possibility to use them to send MQTT, one example could be a little 2.4" screen next to the light switch that could control the Sonos in that room.
The problem I had is that I need everything to be small so that it easily could be fit inside a case or inside the wall behind the screen.

mcModule is the perfect device for this, it is very small and it has MQTT and Uart serial communication that is all you need to have this up and running.

I Am providing a simple example and also a short video so that you could see it in action.

Code loaded to mcModule
Code: [Select]
Define PinMode Pin1 As DigitalInput //RX
Define PinMode Pin3 As DigitalOutput //TX

Class NextionTest
    Shared serial As Uart
    Shared Event Boot()
        // Enable serial communication
        serial = Uart.Create(9600, Pin.Pin3, Pin.Pin1)
    End Event
   
   
    Shared Event Uart0Receive()
        //Data is received
        Dim chr As Integer = serial.Read
        If chr = 1 Then
            //Button 1 clicked
            //Turn on Green LED
            LedGreen = True         
        ElseIf chr = 2 Then
            //Button 2 clicked
            //Turn off Green LED
            LedGreen = False
        ElseIf chr = 3 Then
            //Button 3 clicked
            //Turn on or off Red LED
            LedRed = Not LedRed
        End If     
    End Event
End Class

Video

Please ask questions about this and I will do my best to answer them.

Social Buttons

Like Like x 2 Winner Winner x 1 View List

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: mcModules goes touch
« Reply #1 on: June 15, 2016, 12:47:18 pm »
Very cool Kristofferis! That is awesome and a good showcase of some of the ways that mc-Modules and the mc-Things platform can be used! Please keep us updated as you progress with your projects, we are excited to see more of your use-cases!!
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB
Like Like x 1 View List

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #2 on: June 15, 2016, 12:59:12 pm »
Thanks T2.
I will alao update the code to show how you could update the display with information that is coming to the mcModule with MQTT and also show how the touchscreen could make something happen on another mcModule with MQTT.

I have to say that's it pretty cool that with only two cables from the screen have communication to any device in the world (MQTT)
Like Like x 2 View List

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: mcModules goes touch
« Reply #3 on: June 24, 2016, 04:14:08 am »
Pretty interested to know what touch screen module your using here.

Cheers
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #4 on: June 24, 2016, 04:45:34 am »
Hello.

The Touchscreen that I am using in the above example is a Nextion and the exact model that i used is NX3224T024
It is a 2.4" screen and as you could see in my code it is very simple to communicate with it.
Like Like x 1 View List

EthanSpitz

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: mcModules goes touch
« Reply #5 on: August 03, 2016, 09:54:41 pm »
How did you get the display up and running? It's not clear from the code.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #6 on: August 04, 2016, 02:23:59 am »
The display is configured with Nextion Editor.
It is a simple tool to drag and drop buttons and things like that.

And then you assign what should happen when the different objects is being pushed.

In this simple example I am just sending 1,2 or 3 from the different buttons on the display.

Riverrider

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: mcModules goes touch
« Reply #7 on: August 13, 2016, 12:32:49 pm »
Does one need a level shifter to drive the LCD's UART interface from the mcModule?

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #8 on: August 13, 2016, 12:38:40 pm »
The logical level of the display is 3.3V so no need for a level shifter.

Nick_W

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Re: mcModules goes touch
« Reply #9 on: September 09, 2016, 10:56:51 pm »
I really like this application. I just received a couple of nexion displays (and made a couple of bezels for them).

The display is crazy hard to figure out how to program though. Thei designer is confusing as all hell.

Are you willing to share your files (say on github) so I can get a starting point for this.

It looks like I have to make a bitmap for everything (buttons etc), then upload the whole lot to the display. I have files for the demo that comes with the display, but it looks like a ton of work to get it going.

Any help to get me started would be appreciated.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #10 on: September 10, 2016, 08:55:03 am »
Hello.
I will do my best to help you with this.

I am using Nextion Editor Version 0.38
In that program you drag and drop different "functions" like buttons, text and things like that.
And when you are done you compile and that file should be installed on the display.
You could also debug the project without the need of an display, a very nice feature.

I have uploaded one project on GitHub that will get you started https://github.com/Isaksson/Nextion
It's a project for monitoring temperature and battery.

I have included all images and fonts needed for the project.

Try this and let me know how it goes.

Nick_W

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Re: mcModules goes touch
« Reply #11 on: September 10, 2016, 12:37:46 pm »
Thanks!

I've downloaded the latest Nextion editor, and loaded your project. I'm having a little trouble communicating with the display (I'll figure that out).

Do you have the mcThings program to share that you use for communicating with the display? I've never used the UART interface before, and it would be helpful.

Thanks again. I'll let you know how it goes.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #12 on: September 10, 2016, 01:05:56 pm »
That sounds good  :)

Sure, I pushed some code to the same repository (this code only send data to the display it does not receive any data)

I have made some changes in the code that i not have verified but that does not matter, you will see how it is done.
Receiving data is not any problem, just ask if you need anything about that.

Nick_W

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Re: mcModules goes touch
« Reply #13 on: September 10, 2016, 01:26:51 pm »
Great!

I'll take a look. Any hints on how to upload to the display from the editor? I've set the model (2.4" enhanced), and I'm connected via an FTDI cable. - display powers up and works OK. I have TX to RX and RX to TX (and tried the other way round). Cable shows up at COM7, which I can select, but no communications when I try to upload (goes through the baud rates, then says "Connection failed Forced interrupt!").

I can try the SD card route next, but the serial connection should be simple. I know my cable works (used it on enough other projects).

Bit puzzling. maybe I'll reboot and see what happens...

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: mcModules goes touch
« Reply #14 on: September 10, 2016, 01:30:46 pm »
I have only used the sd-card way of moving my files.
So i don't know, but to move the file with sd-card works good enough, I debug in the emulator so no need for the actual device there.