Skip to content

Commit 8613802

Browse files
authored
Add new M5stack screen sample for text display (#163)
1 parent c87f1a8 commit 8613802

17 files changed

+825
-0
lines changed

samples/Graphics/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ These can also be used with smaller screens on more memory constrained devices.
1515

1616
- ESP32 without PSRAM
1717

18+
## Screens
19+
20+
This demonstrates the low level text display function that is available. Very useful for memory constrained devices with smaller screens.
21+
1822
## SimpleWPF
1923

2024
This contains an animated graphical menu with allows the selection of pages that demonstrates features of the limited WPF that's available in nanoFramework.

samples/Graphics/Screens/README.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Screen samples
2+
3+
These samples demonstrate the low level text display and graphics display functions that are available.
4+
5+
These are very useful for memory constrained devices with smaller screens.
6+
7+
To initialize the screen, `DisplayControl.Initialize`, requires `SPIConfiguration` and `ScreenConfiguration` please check below,
8+
9+
If `backLigtPin` and `reset` are not used, you can use `-1` as a value. `ScreenConfiguration` requires screen size of your actual screen as `screenWidth` and `screenHeight`.
10+
11+
```csharp
12+
DisplayControl.Initialize(
13+
new SpiConfiguration(spiBus, chipSelect, dataCommand, reset, backLightPin),
14+
new ScreenConfiguration(0, 0, screenWidth, screenHeight),
15+
screenBufferSize);
16+
```
17+
18+
For different font family and font sizes, you can generate tinyfont. You can find more information about tinyfont on [this blog](http://informatix.miloush.net/microframework/Utilities/TinyFontTool.aspx)
19+
20+
## M5Stack Screen
21+
22+
[M5Stack Screen](m5stack-screen) was tested in:
23+
24+
- [M5Stack gray](https://shop.m5stack.com/products/grey-development-core?variant=16804796006490)
25+
26+
The features demonstrated are:
27+
28+
- Text display and formatting.
29+
30+
Configuration:
31+
32+
```csharp
33+
// pins for SPI Configuration
34+
backLightPin = 32;
35+
chipSelect = 14;
36+
dataCommand = 27;
37+
reset = 33;
38+
39+
// set MISO, MOSI and CLOCK pins
40+
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
41+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
42+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
43+
```
44+
45+
When running this sample, the end result in the screen looks like this:
46+
47+
![m5stack](images/screen-output.png)
48+
49+
## M5Stick Screen
50+
51+
[M5Stick Screen](m5stick-screen) was tested in:
52+
53+
- [M5StickC plus](https://shop.m5stack.com/collections/stick-series/products/m5stickc-plus-esp32-pico-mini-iot-development-kit)
54+
55+
Before displaying the screen don't forget to initialize AXP192 first, you can check `InitiM5Stick()` in `Program.cs` of `m5stick.screen` sample. The features demonstrated are:
56+
57+
- Using [AXP192](https://github.com/nanoframework/nanoFramework.IoT.Device/tree/develop/devices/Axp192) to initialize the screen
58+
- Graphics display and formatting.
59+
- Text display and formatting.
60+
61+
Configuration:
62+
63+
```csharp
64+
// pins for SPI Configuration
65+
int backLightPin = -1;
66+
int chipSelect = 5;
67+
int dataCommand = 23;
68+
int reset = 18;
69+
70+
// set MISO, MOSI and CLOCK pins
71+
Configuration.SetPinFunction(4, DeviceFunction.SPI1_MISO);
72+
Configuration.SetPinFunction(15, DeviceFunction.SPI1_MOSI);
73+
Configuration.SetPinFunction(13, DeviceFunction.SPI1_CLOCK);
74+
```
75+
76+
When running this sample, the end result in the screen looks like this:
77+
78+
- ToDo
79+
80+
## Wroover
81+
82+
Configuration:
83+
84+
```csharp
85+
// pins for SPI Configuration
86+
backLightPin = 5;
87+
chipSelect = 22;
88+
dataCommand = 21;
89+
reset = 18;
90+
91+
// set MISO, MOSI and CLOCK pins
92+
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
93+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
94+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
95+
```

samples/Graphics/Screens/category.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
graphics
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using nanoFramework.Hardware.Esp32;
2+
using nanoFramework.Presentation.Media;
3+
using nanoFramework.UI;
4+
using System;
5+
using System.Diagnostics;
6+
using System.Threading;
7+
using Windows.Devices.Pwm;
8+
9+
namespace m5stack.screen
10+
{
11+
public class Program
12+
{
13+
public static void Main()
14+
{
15+
Debug.WriteLine("Hello from nanoFramework!");
16+
17+
// Screen init
18+
int chipSelect;
19+
int dataCommand;
20+
int reset;
21+
int backLightPin;
22+
23+
const bool wroover = false;
24+
25+
// Text to display and location on screen
26+
const int screenWidth = 320;
27+
const int screenHeight = 240;
28+
const int screenBufferSize = 30 * 1024;
29+
30+
const int textPosX = 10;
31+
const int textPosY = 0;
32+
const string text = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry.
33+
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
34+
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
35+
It was popularised in the 1960s with the release of Letraset sheets containing
36+
Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
37+
38+
if (wroover)
39+
{
40+
backLightPin = 5;
41+
chipSelect = 22;
42+
dataCommand = 21;
43+
reset = 18;
44+
}
45+
else
46+
{
47+
backLightPin = 32;
48+
chipSelect = 14;
49+
dataCommand = 27;
50+
reset = 33;
51+
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
52+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
53+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
54+
}
55+
56+
Configuration.SetPinFunction(backLightPin, DeviceFunction.PWM1);
57+
DisplayControl.Initialize(new SpiConfiguration(1, chipSelect, dataCommand, reset, backLightPin), new ScreenConfiguration(0, 0, screenWidth, screenHeight), screenBufferSize);
58+
Debug.WriteLine("Screen initialized");
59+
60+
PwmController pwm = PwmController.GetDefault();
61+
pwm.SetDesiredFrequency(44100);
62+
PwmPin pwmPin = pwm.OpenPin(backLightPin);
63+
pwmPin.SetActiveDutyCyclePercentage(0.1);
64+
pwmPin.Start();
65+
66+
Font DisplayFont = Resource.GetFont(Resource.FontResources.segoeuiregular12);
67+
Bitmap charBitmap = new Bitmap(DisplayFont.MaxWidth + 1, DisplayFont.Height);
68+
69+
DisplayControl.Write(text, textPosX, textPosY, screenWidth, screenHeight, DisplayFont, Color.DarkBlue, Color.White);
70+
71+
Thread.Sleep(Timeout.Infinite);
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CSharp.BlankApplication")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CSharp.BlankApplication")]
13+
[assembly: AssemblyCopyright("Copyright © ")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// Version information for an assembly consists of the following four values:
23+
//
24+
// Major Version
25+
// Minor Version
26+
// Build Number
27+
// Revision
28+
//
29+
// You can specify all the values or you can default the Build and Revision Numbers
30+
// by using the '*' as shown below:
31+
// [assembly: AssemblyVersion("1.0.*")]
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]

samples/Graphics/Screens/m5stack-screen/Resource.Designer.cs

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+
<data name="segoeuiregular12" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+
<value>Resources\segoeuiregular12.tinyfnt;System.Byte[], mscorlib, Version=1.10.5.4, Culture=neutral, PublicKeyToken=c07d481e9758c731</value>
123+
</data>
124+
</root>
Binary file not shown.

0 commit comments

Comments
 (0)